tomlokhorst / XcodeEdit

Swift library for reading and writing Xcode project files in OpenStep format
MIT License
206 stars 38 forks source link

Do internal consistency check in initializer #13

Closed tomlokhorst closed 7 years ago

tomlokhorst commented 8 years ago

Based on https://github.com/tomlokhorst/Xcode.swift/pull/12

The XCProjectFile initializer should do a internal consistency check after loading the project file. To prevent runtime crashes on one of the many ! used throughout the code.

I haven't tested this, but my guess is, this should work:

  1. Every 24 character alphanumeric String object reference "somewhere" in the complete object graph is an object reference, and that GUID key should exist in the objects list.
  2. Every object GUID key in the objects should be referenced somewhere in the complete object graph.

If either of these fails, an error like this can be generated:

- BuildFile (46880B8819C43A87006E1F66) references missing fileRef 3EACC98E19EE6D4300EB3C5E
- FileReference `AppDelegate.cpp` (288765A40DF7441C002DB57D) is not used in any BuildFile.

Perhaps a merge conflict?

As a second step, the initializer can take an extra parameter unsafeIgnoreInconsistency: Bool so that the current behaviour can be returned. Perhaps with a better error message: fatalError("Can't find key '3EACC98E19EE6D4300EB3C5E' in objects, ignored in internal inconsistency check. Perhaps a merge conflict?")

tomlokhorst commented 7 years ago

Merged in release/2.0 branch which will be released when Swift 4/Xcode 9 is available.