Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I programmatically add build files to Xcode4?

I've been trying to figure out how to programmatically add files to an Xcode4 project and it seemed like AppleScript would be the way to go, however I'm running into "missing value" errors.

Here's the code I've got:

tell application "Xcode"
    set theProject to first project
    set theTarget to first target of theProject
    set theBuildPhase to compile sources phase of theTarget
    tell first group of theProject
        set theFileRef to make new file reference with properties {full path:"/Users/jeff/Projects/XcodeTest/XcodeTest/MyViewController.h", name:"MyViewController.h", path:"XcodeTest/MyViewController.h", path type:group relative}
        add theFileRef to theProject
    end tell
    --tell theBuildPhase to make new build file with properties {build phase:theBuildPhase, name:"MyViewController.h", file reference:theFileRef, target:theTarget, project:theProject}
end tell

I've tried the commented-out line instead of the add-command as well, but that doesn't work either (I get "missing value").

The 'add' error is:

error "Xcode got an error: file reference id \"251AD3431432472E006E300F\" of Xcode 3 group id \"251AD32C14324645006E300F\" of project \"XcodeTest\" of workspace document \"XcodeTest.xcodeproj/project.xcworkspace\" doesn’t understand the add message." number -1708 from file reference id "251AD3431432472E006E300F" of Xcode 3 group id "251AD32C14324645006E300F" of project "XcodeTest" of workspace document "XcodeTest.xcodeproj/project.xcworkspace"

The "make new reference" does add the file to the list of files in Xcode, but I also need it to be added to the project target so that I can add actions and outlets to the file from Xcode w/o having to first check the checkbox to add it to the "target membership".

like image 240
jstedfast Avatar asked Feb 23 '23 20:02

jstedfast


2 Answers

I ended up sending this question to the devs on the xcode developer list and the response I got was effectively "you can't".

like image 150
jstedfast Avatar answered Feb 25 '23 11:02

jstedfast


This appears to be completely broken in Xcode4, but I've seen a project that does it. I think what they are doing is parsing and modifying the "project.pbxproj" file directly. (this file is hidden inside the xcodeproj bundle)

The file is a GUID soup, but once you look at it for a while it seems possible to safely modify it, especially if you are only adding stuff.

Edit:

Found this stackoverflow answer that might help.

Tutorial or Guide for Scripting XCode Build Phases

like image 23
Calvin Avatar answered Feb 25 '23 10:02

Calvin