From 7b68c8df6b78951e6d04eea62c3d5cc056796993 Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Tue, 7 Apr 2015 19:14:52 +0200 Subject: 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. --- Source/cmGlobalXCodeGenerator.cxx | 16 ++++++++++++++++ Source/cmGlobalXCodeGenerator.h | 1 + 2 files changed, 17 insertions(+) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 0561a05..be40c66 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -592,6 +592,20 @@ void cmGlobalXCodeGenerator::CreateReRunCMakeFile( } //---------------------------------------------------------------------------- + +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() { this->TargetDoneSet.clear(); @@ -3713,6 +3727,8 @@ cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout, cmLocalGenerator* , std::vector& ) { + SortXCodeObjects(); + fout << "// !$*UTF8*$!\n"; fout << "{\n"; cmXCodeObject::Indent(1, fout); diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h index b272f6a..1a69fce 100644 --- a/Source/cmGlobalXCodeGenerator.h +++ b/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, -- cgit v0.12 From 2e0e205e28922c6584a35ce6ec9966485df47b0d Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Tue, 7 Apr 2015 19:13:57 +0200 Subject: Xcode: Indent using tabs --- Source/cmXCodeObject.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/cmXCodeObject.cxx b/Source/cmXCodeObject.cxx index 5a90fd9..33ce8cc 100644 --- a/Source/cmXCodeObject.cxx +++ b/Source/cmXCodeObject.cxx @@ -81,7 +81,7 @@ void cmXCodeObject::Indent(int level, std::ostream& out) { while(level) { - out << " "; + out << "\t"; level--; } } -- cgit v0.12 From 2fe8bca58089fb03f0ffa16792cc15fb741bd22c Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Tue, 7 Apr 2015 19:19:00 +0200 Subject: Xcode: Add comment after root object --- Source/cmGlobalXCodeGenerator.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index be40c66..2e13692 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -3756,7 +3756,8 @@ cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout, cmXCodeObject::PrintList(this->XCodeObjects, fout); } cmXCodeObject::Indent(1, fout); - fout << "rootObject = " << this->RootObject->GetId() << ";\n"; + fout << "rootObject = " << this->RootObject->GetId() + << " /* Project object */;\n"; fout << "}\n"; } -- cgit v0.12 From a723427b6450c1ec77226fb58aa3070a341891a2 Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Tue, 7 Apr 2015 19:20:54 +0200 Subject: Xcode: Remove extra space in PBXProject comment --- Source/cmGlobalXCodeGenerator.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 2e13692..4d98359 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -3386,7 +3386,7 @@ bool cmGlobalXCodeGenerator } configlist->AddAttribute("buildConfigurations", buildConfigurations); - std::string comment = "Build configuration list for PBXProject "; + std::string comment = "Build configuration list for PBXProject"; comment += " \""; comment += this->CurrentProject; comment += "\""; -- cgit v0.12 From 5cb4c8380d9a0f5922a2eed60f6a1fd1274e9141 Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Tue, 7 Apr 2015 20:47:10 +0200 Subject: Xcode: Properly indent PBXFileReference and PBXBuildFile Move indent factor change behind indention of start-of-line. --- Source/cmXCodeObject.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/cmXCodeObject.cxx b/Source/cmXCodeObject.cxx index 33ce8cc..519545a 100644 --- a/Source/cmXCodeObject.cxx +++ b/Source/cmXCodeObject.cxx @@ -91,13 +91,13 @@ void cmXCodeObject::Print(std::ostream& out) { std::string separator = "\n"; int indentFactor = 1; + cmXCodeObject::Indent(2*indentFactor, out); if(this->Version > 15 && (this->IsA == PBXFileReference || this->IsA == PBXBuildFile)) { separator = " "; indentFactor = 0; } - cmXCodeObject::Indent(2*indentFactor, out); out << this->Id << " "; if(!(this->IsA == PBXGroup && this->Comment.size() == 0)) { -- cgit v0.12 From 4bd2544b25655b6e20e5098a5f4cdd973288c106 Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Tue, 7 Apr 2015 22:00:29 +0200 Subject: Xcode: Do not add whitespace after attribute group opening brace This suppresses the extra space that would be generated if the separator is a space. The conditional block is also used in this form elsewhere. --- Source/cmXCodeObject.cxx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/cmXCodeObject.cxx b/Source/cmXCodeObject.cxx index 519545a..72d8e99 100644 --- a/Source/cmXCodeObject.cxx +++ b/Source/cmXCodeObject.cxx @@ -139,7 +139,11 @@ void cmXCodeObject::Print(std::ostream& out) else if(object->TypeValue == ATTRIBUTE_GROUP) { std::map::iterator j; - out << i->first << " = {" << separator; + out << i->first << " = {"; + if(separator == "\n") + { + out << separator; + } for(j = object->ObjectAttributes.begin(); j != object->ObjectAttributes.end(); ++j) { -- cgit v0.12 From 6e8952c19385acb0ff9f58c2a462d91dd0624e05 Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Thu, 9 Apr 2015 10:14:47 +0200 Subject: Xcode: PrintComment will prepend a whitespace itself before the comment --- Source/cmXCode21Object.cxx | 2 +- Source/cmXCodeObject.cxx | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Source/cmXCode21Object.cxx b/Source/cmXCode21Object.cxx index 855e1ad..96f7b0f 100644 --- a/Source/cmXCode21Object.cxx +++ b/Source/cmXCode21Object.cxx @@ -31,7 +31,7 @@ void cmXCode21Object::PrintComment(std::ostream& out) cmSystemTools::ReplaceString(this->Comment, "\"", ""); } } - out << "/* "; + out << " /* "; out << this->Comment; out << " */"; } diff --git a/Source/cmXCodeObject.cxx b/Source/cmXCodeObject.cxx index 72d8e99..e41f282 100644 --- a/Source/cmXCodeObject.cxx +++ b/Source/cmXCodeObject.cxx @@ -98,7 +98,7 @@ void cmXCodeObject::Print(std::ostream& out) separator = " "; indentFactor = 0; } - out << this->Id << " "; + out << this->Id; if(!(this->IsA == PBXGroup && this->Comment.size() == 0)) { this->PrintComment(out); @@ -129,7 +129,7 @@ void cmXCodeObject::Print(std::ostream& out) for(unsigned int k = 0; k < i->second->List.size(); k++) { cmXCodeObject::Indent(4*indentFactor, out); - out << i->second->List[k]->Id << " "; + out << i->second->List[k]->Id; i->second->List[k]->PrintComment(out); out << "," << separator; } @@ -192,7 +192,6 @@ void cmXCodeObject::Print(std::ostream& out) out << " = " << object->Object->Id; if(object->Object->HasComment() && i->first != "remoteGlobalIDString") { - out << " "; object->Object->PrintComment(out); } out << ";" << separator; -- cgit v0.12 From a6331eb851c132d3d0496e738886ad76e13a92a0 Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Thu, 9 Apr 2015 10:48:33 +0200 Subject: Xcode: Let PrintComment decide if the comment is non-empty --- Source/cmXCode21Object.cxx | 4 ++++ Source/cmXCodeObject.cxx | 5 +---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/cmXCode21Object.cxx b/Source/cmXCode21Object.cxx index 96f7b0f..f30f700 100644 --- a/Source/cmXCode21Object.cxx +++ b/Source/cmXCode21Object.cxx @@ -31,6 +31,10 @@ void cmXCode21Object::PrintComment(std::ostream& out) cmSystemTools::ReplaceString(this->Comment, "\"", ""); } } + if(this->Comment.empty()) + { + return; + } out << " /* "; out << this->Comment; out << " */"; diff --git a/Source/cmXCodeObject.cxx b/Source/cmXCodeObject.cxx index e41f282..b9c41f3 100644 --- a/Source/cmXCodeObject.cxx +++ b/Source/cmXCodeObject.cxx @@ -99,10 +99,7 @@ void cmXCodeObject::Print(std::ostream& out) indentFactor = 0; } out << this->Id; - if(!(this->IsA == PBXGroup && this->Comment.size() == 0)) - { - this->PrintComment(out); - } + this->PrintComment(out); out << " = {"; if(separator == "\n") { -- cgit v0.12 From 6693590f8144a905b423ca03fa8ed98df4468bae Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Thu, 9 Apr 2015 11:04:35 +0200 Subject: Xcode: Refine quoting rules for Strings $ and . do not need to be quoted, but brackets and * must be to not confuse the Xcode parser. --- Source/cmXCodeObject.cxx | 2 +- Tests/RunCMake/XcodeProject/XcodeFileType-check.cmake | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/cmXCodeObject.cxx b/Source/cmXCodeObject.cxx index b9c41f3..e72d315 100644 --- a/Source/cmXCodeObject.cxx +++ b/Source/cmXCodeObject.cxx @@ -243,7 +243,7 @@ void cmXCodeObject::PrintString(std::ostream& os,std::string String) bool needQuote = (String.empty() || String.find("//") != String.npos || - String.find_first_of(" <>.+-=@$[],") != String.npos); + String.find_first_of(" <>+-*=@[](){},") != String.npos); const char* quote = needQuote? "\"" : ""; // Print the string, quoted and escaped as necessary. diff --git a/Tests/RunCMake/XcodeProject/XcodeFileType-check.cmake b/Tests/RunCMake/XcodeProject/XcodeFileType-check.cmake index 7882d7f..1847bc9 100644 --- a/Tests/RunCMake/XcodeProject/XcodeFileType-check.cmake +++ b/Tests/RunCMake/XcodeProject/XcodeFileType-check.cmake @@ -1,6 +1,6 @@ set(expect-default "explicitFileType = sourcecode") -set(expect-explicit "explicitFileType = \"sourcecode.c.h\"") -set(expect-lastKnown "lastKnownFileType = \"sourcecode.c.h\"") +set(expect-explicit "explicitFileType = sourcecode.c.h") +set(expect-lastKnown "lastKnownFileType = sourcecode.c.h") foreach(src default explicit lastKnown) file(STRINGS ${RunCMake_TEST_BINARY_DIR}/XcodeFileType.xcodeproj/project.pbxproj actual-${src} REGEX "PBXFileReference.*src-${src}") -- cgit v0.12