[Cmake-commits] CMake branch, next, updated. v3.5.2-1248-gcb2e171

Brad King brad.king at kitware.com
Thu May 5 10:23:23 EDT 2016


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  cb2e171b63dc6b0e41973d81a295189adb2342a7 (commit)
       via  64956cc8a304e2692a5c56525ab9db1d03c7ac82 (commit)
      from  cd4d618661d84af9106e272e7674de50303b96cf (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 -----------------------------------------------------------------
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=cb2e171b63dc6b0e41973d81a295189adb2342a7
commit cb2e171b63dc6b0e41973d81a295189adb2342a7
Merge: cd4d618 64956cc
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Thu May 5 10:23:22 2016 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Thu May 5 10:23:22 2016 -0400

    Merge topic 'ghs-hash-object-locations' into next
    
    64956cc8 GHS: Shorten long object paths with duplicate source names


https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=64956cc8a304e2692a5c56525ab9db1d03c7ac82
commit 64956cc8a304e2692a5c56525ab9db1d03c7ac82
Author:     Geoff Viola <geoffrey.viola at asirobots.com>
AuthorDate: Wed May 4 22:49:27 2016 -0600
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Thu May 5 10:21:47 2016 -0400

    GHS: Shorten long object paths with duplicate source names
    
    Detect when the resulting object path is too long and compute an
    alternative name using a hash.

diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx
index f845c59..ddb33cd 100644
--- a/Source/cmGhsMultiTargetGenerator.cxx
+++ b/Source/cmGhsMultiTargetGenerator.cxx
@@ -114,7 +114,7 @@ cmGhsMultiTargetGenerator::AddSlashIfNeededToPath(std::string const &input)
 
 void cmGhsMultiTargetGenerator::Generate()
 {
-  const std::vector<cmSourceFile *> objectSources = this->GetSources();
+  std::vector<cmSourceFile *> objectSources = this->GetSources();
   if (!objectSources.empty() && this->IncludeThisTarget())
     {
     if (!cmSystemTools::FileExists(this->AbsBuildFilePath.c_str()))
@@ -154,7 +154,11 @@ void cmGhsMultiTargetGenerator::Generate()
       }
     this->WriteCustomCommands();
 
-    this->WriteSources(objectSources);
+    std::map<const cmSourceFile *, std::string> objectNames =
+        cmGhsMultiTargetGenerator::GetObjectNames(
+            &objectSources, this->LocalGenerator, this->GeneratorTarget);
+
+    this->WriteSources(objectSources, objectNames);
     }
 }
 
@@ -484,44 +488,65 @@ void cmGhsMultiTargetGenerator::WriteCustomCommandsHelper(
 
 std::map<const cmSourceFile *, std::string>
 cmGhsMultiTargetGenerator::GetObjectNames(
-    const std::vector<cmSourceFile *> &objectSources)
+    std::vector<cmSourceFile *> *const objectSources,
+    cmLocalGhsMultiGenerator *const localGhsMultiGenerator,
+    cmGeneratorTarget *const generatorTarget)
 {
-  bool found_duplicate = false;
-  std::set<std::string> filenames;
+  std::map<std::string, std::vector<cmSourceFile *>> filenameToSource;
+  std::map<cmSourceFile *, std::string> sourceToFilename;
   for(std::vector<cmSourceFile *>::const_iterator
-      sf = objectSources.begin(); sf != objectSources.end(); ++sf)
+      sf = objectSources->begin(); sf != objectSources->end(); ++sf)
     {
     const std::string filename =
         cmSystemTools::GetFilenameName((*sf)->GetFullPath());
     const std::string lower_filename = cmSystemTools::LowerCase(filename);
-    if (filenames.end() != filenames.find(lower_filename))
+    filenameToSource[lower_filename].push_back(*sf);
+    sourceToFilename[*sf] = lower_filename;
+    }
+
+  std::vector<cmSourceFile *> duplicateSources;
+  for (std::map<std::string, std::vector<cmSourceFile *>>::const_iterator
+       msvSourceI = filenameToSource.begin();
+       msvSourceI != filenameToSource.end(); ++msvSourceI)
+    {
+    if (msvSourceI->second.size() > 1)
       {
-      found_duplicate = true;
+      duplicateSources.insert(duplicateSources.end(),
+                              msvSourceI->second.begin(),
+                              msvSourceI->second.end());
       }
-    filenames.insert(lower_filename);
     }
 
-  std::map<const cmSourceFile *, std::string> objectNames;
-  if (found_duplicate)
+  std::map<const cmSourceFile *, std::string> objectNamesCorrected;
+
+  for (std::vector<cmSourceFile *>::const_iterator sf =
+           duplicateSources.begin();
+       sf != duplicateSources.end(); ++sf)
     {
-    for(std::vector<cmSourceFile *>::const_iterator
-        sf = objectSources.begin(); sf != objectSources.end(); ++sf)
+    static std::string::size_type const MAX_FULL_PATH_LENGTH = 247;
+    std::string const longestObjectDirectory(
+        cmGhsMultiTargetGenerator::ComputeLongestObjectDirectory(
+    localGhsMultiGenerator, generatorTarget, *sf));
+    std::string fullFilename = (*sf)->GetFullPath();
+    bool const ObjPathFound = cmLocalGeneratorCheckObjectName(
+        fullFilename, longestObjectDirectory.size(), MAX_FULL_PATH_LENGTH);
+    if (!ObjPathFound)
       {
-      std::string full_filename = (*sf)->GetFullPath();
-      cmsys::SystemTools::ReplaceString(full_filename, ":/", "_");
-      cmsys::SystemTools::ReplaceString(full_filename, "/", "_");
-      objectNames[*sf] = full_filename;
+      cmSystemTools::Error("Object path \"", fullFilename.c_str(),
+                           "\" too long", "");
       }
+    cmsys::SystemTools::ReplaceString(fullFilename, ":/", "_");
+    cmsys::SystemTools::ReplaceString(fullFilename, "/", "_");
+    objectNamesCorrected[*sf] = fullFilename;
     }
 
-  return objectNames;
+  return objectNamesCorrected;
 }
 
 void cmGhsMultiTargetGenerator::WriteSources(
-  std::vector<cmSourceFile *> const &objectSources)
+    std::vector<cmSourceFile *> const &objectSources,
+    std::map<const cmSourceFile *, std::string> const &objectNames)
 {
-  std::map<const cmSourceFile *, std::string> objectNames =
-    cmGhsMultiTargetGenerator::GetObjectNames(objectSources);
   for (std::vector<cmSourceFile *>::const_iterator si = objectSources.begin();
        si != objectSources.end(); ++si)
     {
@@ -646,6 +671,30 @@ cmGhsMultiTargetGenerator::GetOutputFilename(const std::string &config) const
   return outputFilename;
 }
 
+std::string cmGhsMultiTargetGenerator::ComputeLongestObjectDirectory(
+    cmLocalGhsMultiGenerator const *localGhsMultiGenerator,
+    cmGeneratorTarget *const generatorTarget, cmSourceFile *const sourceFile)
+{
+  std::string dir_max;
+  dir_max +=
+      localGhsMultiGenerator->GetMakefile()->GetCurrentBinaryDirectory();
+  dir_max += "/";
+  dir_max += generatorTarget->Target->GetName();
+  dir_max += "/";
+  std::vector<cmSourceGroup> sourceGroups(
+      localGhsMultiGenerator->GetMakefile()->GetSourceGroups());
+  char const *const sourceFullPath = sourceFile->GetFullPath().c_str();
+  cmSourceGroup *sourceGroup =
+      localGhsMultiGenerator->GetMakefile()->FindSourceGroup(sourceFullPath,
+                                                             sourceGroups);
+  std::string const sgPath(sourceGroup->GetFullName());
+  dir_max += sgPath;
+  dir_max += "/Objs/libs/";
+  dir_max += generatorTarget->Target->GetName();
+  dir_max += "/";
+  return dir_max;
+}
+
 bool cmGhsMultiTargetGenerator::IsNotKernel(std::string const &config,
                                             const std::string &language)
 {
diff --git a/Source/cmGhsMultiTargetGenerator.h b/Source/cmGhsMultiTargetGenerator.h
index 93761f2..9f18eeb 100644
--- a/Source/cmGhsMultiTargetGenerator.h
+++ b/Source/cmGhsMultiTargetGenerator.h
@@ -87,15 +87,22 @@ private:
   void
   WriteCustomCommandsHelper(std::vector<cmCustomCommand> const &commandsSet,
                             cmTarget::CustomCommandType commandType);
-  void WriteSources(std::vector<cmSourceFile *> const &objectSources);
+  void WriteSources(
+      std::vector<cmSourceFile *> const &objectSources,
+      std::map<const cmSourceFile *, std::string> const &objectNames);
   static std::map<const cmSourceFile *, std::string>
-  GetObjectNames(const std::vector<cmSourceFile *> &objectSources);
+  GetObjectNames(std::vector<cmSourceFile *> *objectSources,
+                 cmLocalGhsMultiGenerator *localGhsMultiGenerator,
+                 cmGeneratorTarget *generatorTarget);
   static void WriteObjectLangOverride(cmGeneratedFileStream *fileStream,
                                       cmSourceFile *sourceFile);
   static void WriteObjectDir(cmGeneratedFileStream *fileStream,
                              std::string const &dir);
   std::string GetOutputDirectory(const std::string &config) const;
   std::string GetOutputFilename(const std::string &config) const;
+  static std::string ComputeLongestObjectDirectory(
+      cmLocalGhsMultiGenerator const *localGhsMultiGenerator,
+      cmGeneratorTarget *generatorTarget, cmSourceFile *const sourceFile);
 
   bool IsNotKernel(std::string const &config, const std::string &language);
   static bool DetermineIfTargetGroup(const cmGeneratorTarget* target);
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 6c2ba05..6db18f7 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -2667,7 +2667,6 @@ cmLocalGeneratorShortenObjectName(std::string& objName,
     }
 }
 
-static
 bool cmLocalGeneratorCheckObjectName(std::string& objName,
                                      std::string::size_type dir_len,
                                      std::string::size_type max_total_len)
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
index 0bad0d6..33db68c 100644
--- a/Source/cmLocalGenerator.h
+++ b/Source/cmLocalGenerator.h
@@ -404,4 +404,10 @@ private:
   void ComputeObjectMaxPath();
 };
 
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+bool cmLocalGeneratorCheckObjectName(std::string &objName,
+                                     std::string::size_type dir_len,
+                                     std::string::size_type max_total_len);
+#endif
+
 #endif

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

Summary of changes:
 Source/cmGhsMultiTargetGenerator.cxx |   91 ++++++++++++++++++++++++++--------
 Source/cmGhsMultiTargetGenerator.h   |   11 +++-
 Source/cmLocalGenerator.cxx          |    1 -
 Source/cmLocalGenerator.h            |    6 +++
 4 files changed, 85 insertions(+), 24 deletions(-)


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list