浏览代码

Xcode: Sort Xcode objects by Id

this patch series aims to minimize deltas between the CMake Xcode
generator and Xcode itself. It was started by the observation that
if one makes any change to the project within Xcode (e.g. to see
how a variable is called internally) the user cannot diff the CMake
project and the one stored by Xcode afterwards.

Xcode keeps the objects ordered by the object id.
Because cmake stores them into an unordered container
at creation time they must be sorted before writing the
pbxproj file.

I tested this series with Xcode 6.3 and Xcode 3.2. Both show a
reduced diff after this series was applied.
Gregor Jasny 10 年之前
父节点
当前提交
7b68c8df6b
共有 2 个文件被更改,包括 17 次插入0 次删除
  1. 16 0
      Source/cmGlobalXCodeGenerator.cxx
  2. 1 0
      Source/cmGlobalXCodeGenerator.h

+ 16 - 0
Source/cmGlobalXCodeGenerator.cxx

@@ -591,6 +591,20 @@ void cmGlobalXCodeGenerator::CreateReRunCMakeFile(
                    mf->GetHomeOutputDirectory()) << "\n";
 }
 
+//----------------------------------------------------------------------------
+
+static bool objectIdLessThan(cmXCodeObject* l, cmXCodeObject* r)
+{
+  return l->GetId() < r->GetId();
+}
+
+//----------------------------------------------------------------------------
+void cmGlobalXCodeGenerator::SortXCodeObjects()
+{
+  std::sort(this->XCodeObjects.begin(), this->XCodeObjects.end(),
+            objectIdLessThan);
+}
+
 //----------------------------------------------------------------------------
 void cmGlobalXCodeGenerator::ClearXCodeObjects()
 {
@@ -3713,6 +3727,8 @@ cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout,
                                           cmLocalGenerator* ,
                                           std::vector<cmLocalGenerator*>& )
 {
+  SortXCodeObjects();
+
   fout << "// !$*UTF8*$!\n";
   fout << "{\n";
   cmXCodeObject::Indent(1, fout);

+ 1 - 0
Source/cmGlobalXCodeGenerator.h

@@ -150,6 +150,7 @@ private:
                            cmXCodeObject* buildSettings,
                            const std::string& buildType);
   std::string ExtractFlag(const char* flag, std::string& flags);
+  void SortXCodeObjects();
   // delete all objects in the this->XCodeObjects vector.
   void ClearXCodeObjects();
   bool CreateXCodeObjects(cmLocalGenerator* root,