Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit More Comments in Xcode Project Files #243

Merged
merged 5 commits into from
Mar 9, 2018
Merged

Conversation

briantkelley
Copy link
Contributor

@briantkelley briantkelley commented Mar 7, 2018

Short description 📝

Update xcproj to support the comment property and to fix diff noise when creating plist entires for PBXVariantGroup, PBXProject, and PBXTarget.

Solution 📦

Add support for the comment property via a new PBXContainerItem class, which follows Xcode's design based on a Google class-dump header search. Update comment generation PBXVariantGroup, PBXProject, and PBXTarget to eliminate diff noise found when writing the 218 with xcproj.

Implementation 👩‍💻👨‍💻

  • Add PBXContainerItem to support the comment property, matching the behavior from a class-dump search, and make it the super class of PBXBuildPhase and PBXTarget.
  • When creating the comment fo PBXVariantGroup, fall back to path if name is nil.
  • Similarly, when creating the comment for PBXProject.mainGroup and PBXProject.productRefGroup, fall back to path if name is nil.
  • PBXTarget.buildRules emits the isa as the comment, similar to the dependencies property.

This change is Reviewable

@briantkelley briantkelley changed the title Fix comments Emite More Comments in Xcode Project Files Mar 7, 2018
@briantkelley briantkelley changed the title Emite More Comments in Xcode Project Files Emit More Comments in Xcode Project Files Mar 7, 2018
@@ -88,7 +88,7 @@ public class PBXTarget: PBXObject {
}

func plistValues(proj: PBXProj, isa: String, reference: String) -> (key: CommentedString, value: PlistValue) {
var dictionary: [CommentedString: PlistValue] = [:]
var dictionary = plistValues(proj: proj, reference: reference)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be super.plistValues?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I can update that to make it more clear. This method has an isa: named argument so this code isn't infinitely recursive. After reading your comment I was like, wait, how does this work? :)

Copy link
Contributor

@pepicrft pepicrft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment. Out of curiosity, how did you do the dump-header search that you mentioned?

@briantkelley
Copy link
Contributor Author

I just searched around PBXTarget.h until I found something interesting. PBXContainerItem.h has the comments property, which PBXBuildPhase and PBXTarget inherit via the PBXProjectItem class.

Older versions of Xcode (Xcode 3 and prior) supported user comments on build phases and targets. Add support for loading and writing comments from old project files so the project is left unchanged after a round trip.

The class name PBXContainerItem was chosen to match the class name used by Xcode which introduces the comments property in to the hierarchy.
The the name property is not explicitly set, Xcode will use the path to populate the object’s comment. Update xcproj with this behavior to eliminate noise in diffs.
The mainGroup property’s comment is the group’s name or path, if either exists. Similarly, use the path for the productRefGroup if the name property isn’t set.
Xcode appends a generic PBXBuildRule comment to a target’s build rules, similar to the target dependencies. Update xcproj to do the same to eliminate diffs.
@yonaskolb
Copy link
Collaborator

Where is the comment property set within the Xcode UI?

@briantkelley
Copy link
Contributor Author

As far as I know, the UI for editing comments was eliminated in Xcode 4, but we still have a lot of comments throughout our 218 Xcode projects, so even though it's seemingly an obsolete feature, I'd like to eliminate diffs.

@briantkelley briantkelley mentioned this pull request Mar 9, 2018
7 tasks
@briantkelley briantkelley merged commit 475f092 into master Mar 9, 2018
@pepicrft pepicrft deleted the fix-comments branch March 9, 2018 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants