CocoaPods / CocoaPods/Xcodeproj

Xcode project corruption due to UUID conflict

Open
#681 17 comments 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
2.4k
Forks
488
PR merge metrics
No merged PRs in 30d

Description

We run into a race condition/UUID conflict that seems to be related to changes made in https://github.com/CocoaPods/Xcodeproj/pull/627

Our sizeable project uses Cocoapods, and when testing with 1.7.0.beta.2 we run into an issue where a specific number of files included in the Pods project resulted in an apparent UUID conflict, which results in a corrupted Pods.xcodeproj generated.

The issue seems to reproduce only when:
* Pods project getting constructed in the memory has a specific number of files (meaning adding or removing a file fixes the issue)
* Before saving the Pods project, we add a new file ref in post-install hook:
`common_ref = project.new_file("Some.common.xcconfig")`

After the project has been saved, the newly added file reference gets assigned a already existing UUID (46EB2E00000000) and replaces `rootObject`. With this, the project gets corrupted as root object no longer points to an expected data type (`PBXFileReference` instead of `PBXProject`).

```
% xcodeproj show Pods/Pods.xcodeproj
Traceback (most recent call last):
7: from /Users/jsuliga/.rvm/gems/ruby-2.6.1/bin/xcodeproj:23:in `'
6: from /Users/jsuliga/.rvm/gems/ruby-2.6.1/bin/xcodeproj:23:in `load'
5: from /Users/jsuliga/.rvm/gems/ruby-2.6.1/gems/xcodeproj-1.8.2/bin/xcodeproj:10:in `'
4: from /Users/jsuliga/.rvm/gems/ruby-2.6.1/gems/claide-1.0.2/lib/claide/command.rb:334:in `run'
3: from /Users/jsuliga/.rvm/gems/ruby-2.6.1/gems/xcodeproj-1.8.2/lib/xcodeproj/command/show.rb:46:in `run'
2: from /Users/jsuliga/.rvm/gems/ruby-2.6.1/gems/xcodeproj-1.8.2/lib/xcodeproj/command.rb:60:in `xcodeproj'
1: from /Users/jsuliga/.rvm/gems/ruby-2.6.1/gems/xcodeproj-1.8.2/lib/xcodeproj/project.rb:112:in `open'
/Users/jsuliga/.rvm/gems/ruby-2.6.1/gems/xcodeproj-1.8.2/lib/xcodeproj/project.rb:231:in `initialize_from_file': undefined method `product_ref_group' for # (NoMethodError)

```
I'm still trying to find a self-contained project that reproduces the issue, but it's been quite challenging. Saving the project before adding the new reference seems to work around the issue, but causes us to double-save the project which is wasteful.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the changes in pull request 627 and the failure path at lib/xcodeproj/project.rb:231, initialize_from_file. Reproduce the post-install project.new_file("Some.common.xcconfig") case around saving, then verify that generated projects retain a PBXProject rootObject and unique UUIDs; a self-contained reproduction or regression test is still needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.