Fix formatting of PBXFileReference

Ensure the formatting of PBXContainerItemProxy is identical to
the one used by Xcode to make comparison of generated project
with the upgraded version easier.

If the name and path property of the PBXFileReference, then the
name must be ommitted when generating the project. If the name
is not set, the object reference needs to use the path in its
comment (this is usually the case for target outputs).

Bug: chromium/1071055
Change-Id: I30d49d7423eea642e066206a0f601a6608c21885
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/8084
Reviewed-by: Brett Wilson <brettw@chromium.org>
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
diff --git a/src/gn/xcode_object.cc b/src/gn/xcode_object.cc
index de2975c..ac971fc 100644
--- a/src/gn/xcode_object.cc
+++ b/src/gn/xcode_object.cc
@@ -516,6 +516,10 @@
   return name_;
 }
 
+std::string PBXFileReference::Comment() const {
+  return !name_.empty() ? name_ : path_;
+}
+
 void PBXFileReference::Print(std::ostream& out, unsigned indent) const {
   const std::string indent_str(indent, '\t');
   const IndentRules rules = {true, 0};
@@ -533,7 +537,7 @@
       PrintProperty(out, rules, "lastKnownFileType", GetSourceType(ext));
   }
 
-  if (!name_.empty())
+  if (!name_.empty() && name_ != path_)
     PrintProperty(out, rules, "name", name_);
 
   DCHECK(!path_.empty());
diff --git a/src/gn/xcode_object.h b/src/gn/xcode_object.h
index c630177..9458840 100644
--- a/src/gn/xcode_object.h
+++ b/src/gn/xcode_object.h
@@ -228,6 +228,7 @@
   // PBXObject implementation.
   PBXObjectClass Class() const override;
   std::string Name() const override;
+  std::string Comment() const override;
   void Print(std::ostream& out, unsigned indent) const override;
 
   const std::string& path() const { return path_; }