kronenthaler / mod-pbxproj

A python module to manipulate XCode projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[FEAT] Support XML format of pbxproj

yeswecan opened this issue · comments

Hello there!
The issue arises in the XCode projects generated via openFrameworks (https://github.com/openframeworks/openFrameworks) projectGenerator that generates projects in XML format that it creates by modifying this template: https://github.com/openframeworks/openFrameworks/blob/b674f7ec1f41d8f0fcfea86e3d3d3df3e9bdcf36/scripts/templates/osx/emptyExample.xcodeproj/project.pbxproj

If you open a project in XCode and then save it with some minimal change, it'll open, but without it it'll crash, apparently expecting JSON (?). Would be glad if anyone has anything to tell on this! Thanks.

Thank you for report.

This project is a specialized parser for what it's calle the openstep format, which is indeed a JSON-like format.

Xcode can interpret both old XML-plist format (what you have) and the new openstep format. This project is not Xcode and only knows how to read the latter.

However, there is an utility tool on macos that allows to transform the XML to the openstep:

plutil -convert json <your-file> -o <target-file>

This will convert it and allow this library to parse it appropriately.

On a second thought. This could be an improvement for the pbxproj project. Be able to open other formats, in case of failure of this format.

Hey @kronenthaler and thanks for paying attention to this. Unfortunately, the way you recommended didn't work. After plutil, here's exception that I got:

  File "/Users/zebra/anaconda3/lib/python3.7/site-packages/pbxproj/XcodeProject.py", line 92, in load
    tree = osp.OpenStepDecoder.ParseFromFile(file)
  File "/Users/zebra/anaconda3/lib/python3.7/site-packages/openstep_parser/openstep_parser.py", line 40, in ParseFromFile
    return cls.ParseFromString(fp.read())
  File "/Users/zebra/anaconda3/lib/python3.7/site-packages/openstep_parser/openstep_parser.py", line 46, in ParseFromString
    return OpenStepDecoder()._parse(str)
  File "/Users/zebra/anaconda3/lib/python3.7/site-packages/openstep_parser/openstep_parser.py", line 55, in _parse
    result, index = self._parse_dictionary(str, index)
  File "/Users/zebra/anaconda3/lib/python3.7/site-packages/openstep_parser/openstep_parser.py", line 67, in _parse_dictionary
    index = self._parse_dictionary_entry(str, index, obj)
  File "/Users/zebra/anaconda3/lib/python3.7/site-packages/openstep_parser/openstep_parser.py", line 94, in _parse_dictionary_entry
    raise Exception("Expected = after a key. Found {1} @ {0}".format(index, str[index]))
Exception: Expected = after a key. Found 3 @ 24519

Let me know if I can provide any other info or what I should try to do to fix this.

There is one more thing you can try out...

You can convert the XML into JSON, and then initialize the XcodeProject directly.

project = XcodeProject(json.loads(str), "<your-path-to-the-project.pbxproj>")
# your operations here.

In the end the XcodeProject.load(path), it's just an alias of the above.

Important:

  1. To specify the path of the project were you want it to be saved.
  2. The file will be saved in the new format, which poses no problem for Xcode. But better warn you if you were to manipulate it afterwards with a normal XML tool.

Hey @kronenthaler !
Fortunately I was able to load the project in my script following your advice, by using a different load() function. After that I had to add a few None checks to Pbxproj and it worked. Here's the fork if you want to check it out:
yeswecan@325b3aa

I can also PR if you want. Thanks again!

Good to hear. One question, is the project you are loading completely blank?

Good to hear. One question, is the project you are loading completely blank?

No it is not. openFrameworks project generator generates projects by modifying this template file (on OSX):
https://github.com/openframeworks/openFrameworks/blob/patch-release/scripts/templates/osx/emptyExample.xcodeproj/project.pbxproj