I'd like to setup a macro in XCode 4 to checkout the current file from Perforce. How can I do this? I 开发者_StackOverflow社区do not have perforce integrated with my project and do not wish to do so. This is pretty easy in Visual Studio but I don't know the XCode equivalent.
Just came across this at Perforce.com as their means of making this work. I tried it, and it's pretty good.
http://answers.perforce.com/articles/KB/2997
As per the comment, it works in Xcode 5 as well.
And now it's tested and working in Xcode 6!
EDIT:
If that doesn't work, and you're using OS X Mavericks, this guy fixed the script to keep working. Just make sure the script references p4 properly. I had to change it from /usr/local/bin/p4
to /usr/bin/p4
.
http://forums.perforce.com/index.php?/topic/2830-xcode-501-x-mavericks-perforce-integration-not-working/#entry11319
- Make sure that the 'p4' command line tool is installed in '/usr/local/bin/'.
- Verify that your Perforce environment variables are configured correctly. I use a 'perforce.rc' file at the root of every client workspacewith the name of the client (P4CLIENT)and port (P4PORT). Don't forget about P4USER, P4PASSWD, P4CONFIG, etc...
- Create the following script in your ~/bin folder and make sure the permissions are set so it is executable (755 should work).
- Go to the Preferences in Xcode and select "behaviors".
- Scroll down to "Unlock file"
- Scroll down some more and select the checkbox next to "Run"
- Choose "Choose Script..." and point it to the following script:
xcodeunlock.sh
#!/bin/bash
# Xcode4 doesn't setup the environment
source ~/.bashrc
# Delete the URL part from the file passed in
fn=${BASH_ARGV#file://localhost}
echo "fn=" $fn
if [ -a ${fn} ]; then
res=$(/usr/local/bin/p4 edit ${fn})
# TODO: Report the status back to the user in Xcode
# This output goes to the console.
echo $res
else
echo "FnF" ${fn}
fi
Once this is set up correctly, unlocking a file in Xcode should run this script and attempt to checkout the file. Unfortunately any output goes to '/var/log/system.log'. I'm not sure how to notify Xcode 4 of a failure in this script.
It's maddening trying to get XCode to work with Perforce. Here is a solution I came up with that is:
- Quick to get set up
- Easy to burn into your muscle-memory so you don't have to think to check files out
- Doesn't require any mousing at all
One-time setup as follows:
- Download and install the free "DTerm" app from Decimus Software.
- Make sure you have the Perforce command-line utility installed. Type "p4" at a Terminal window prompt, and see if it recognizes this command. If not, you need to go to Perforce's website and find and download what they currently call "The Perforce Command-Line Client (P4)". There's no installer; just save it from your browser right into
/usr/bin
(or whatever) and do a chmod +x on it. For official setup notes, and if you need to do any custom environmental variable tricks, please see this tech note.
Once you've done this, let's say you are in XCode and you are viewing a source code file that you want to check out. Here's the rigamarole:
- Have the file showing in the active XCode editor
- Hit
Shift Command Enter
to get a DTerm window - Type
p4 edit
and then hitShift Command V
to paste in the filename of the active file, and hit return - Perforce checks the file out and DTerm shows you the status/errors.
- Hit 'escape' to dismiss the DTerm window
- Begin making your changes to the file in XCode. XCode may (erroneously) say that the file is read-only, because it's dumb and isn't aware that it's been made from read-only to read-write, so you have to hit Allow Editing. I didn't trust this at first and double-checked it a few times, but now I have blind faith that it's doing the right thing.
I haven't set this up in a while, so please let me know if you run into any glitches and I'll update my info here to make it as painless as possible. But otherwise, this is the best solution I've found.
精彩评论