On Jan 20, 2009, at 7:46 PM, Cathleen Faye Monzon wrote: Hello,
I'd like to ask if there is a way to modify, duplicate or add a target and its build settings through perl scripts or AppleScript? I've tried to check if I can manually modify entries in the project.pbxproj file but it doesn't seem to be a straightforward as I thought it would. I am also looking into the possibility of automating the process of adding new targets and modifying the build settings to make it easier for other users.
Thanks.
The project.pbxproj file inside the xcodeproj directory is just a plist. There are different ways to edit a plist. Look up plists in some of the documentation and you will see different ways to do this. You can, for example, use AppleScript. You have AppleScript read it in as a dictionary of arrays and dictionaries and then you write it out the data structures again, as a plist. And there are libraries in perl which let your read in and write out plists, but I have not looked at them in years. They probably still get used within Apple, though.
A target in a project, for example, is just a bunch of stuff arranged in certain ways in arrays and dictionaries inside the plist.
You can actually use the /usr/bin/defaults command-line tool. If you look to its man page, you will see that you can use, as a "domain", the full path of a plist file. So, then you use the defaults command to write something to this "domain" and it saves changes to the plist. The syntax for putting in arrays and dictionaries and things into a plist can get quirky. Lots of careful escaping of this or that character has to occur. But it is useful.
One thing to keep in mind is that if you change the plist under the covers and get something wrong, Xcode will probably either just not open the project, perhaps crash, or do something else strange. So, make copies of everything, write your scripts defensively and test thoroughly. As for the "straightforward-ness" you were asking about, it won't happen. Use Xcode to do something, see the diffs and so exactly, and I mean exactly, the same thing, and it should be fine. What that things get double-quotes or not, or camelCase or not, etc, etc, etc. Getting something almost right in the plist does not count and Xcide will not be happy with you.
cheers - ray
|