Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perforce Checkout Macro for XCode4 [duplicate]

I'd like to setup a macro in XCode 4 to checkout the current file from Perforce. How can I do this? I 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.

like image 367
LordCecil Avatar asked Apr 03 '11 20:04

LordCecil


3 Answers

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

like image 118
Almo Avatar answered Nov 05 '22 05:11

Almo


  1. Make sure that the 'p4' command line tool is installed in '/usr/local/bin/'.
  2. 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...
  3. Create the following script in your ~/bin folder and make sure the permissions are set so it is executable (755 should work).
  4. Go to the Preferences in Xcode and select "behaviors".
  5. Scroll down to "Unlock file"
  6. Scroll down some more and select the checkbox next to "Run"
  7. 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.

like image 41
Mark Avatar answered Nov 05 '22 07:11

Mark


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:

  1. Download and install the free "DTerm" app from Decimus Software.
  2. 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:

  1. Have the file showing in the active XCode editor
  2. Hit Shift Command Enter to get a DTerm window
  3. Type p4 edit and then hit Shift Command V to paste in the filename of the active file, and hit return
  4. Perforce checks the file out and DTerm shows you the status/errors.
  5. Hit 'escape' to dismiss the DTerm window
  6. 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.

like image 26
Goffredo Avatar answered Nov 05 '22 07:11

Goffredo