11 Nov 2008, 1:00am
Programming:
by

3 comments

Configuring Perforce command line client P4 on Mac OS X

I wrote a post yesterday about setting up the Perforce server P4D on Mac OS X once you’ve done that all that is left is to configure P4V the visual client and P4 the command line client. Fortunately P4V has a helpful set-up wizard to help you configure it for the first time: connect to the server, create your new user account, new client spec and sync up for the first time.

The command line utility P4 takes a little bit more configuration via environment variables which is not quite as simple as setting up P4V, so I thought I would document it. The first thing I did was run P4V and configured it, this has the side effect of working out the perforce port, creating a user account and associated client spec.  Take a note of the username, clientspec and perforce port as you setup P4V, you’ll use those values to configure P4.

Note for this to work you need to have P4 already set-up in your system’s path variable. If you don’t have P4 in your path when you type ‘p4‘ and hit enter in a terminal window you will get a response along the lines of ‘-bash: p4: command not found‘. If you don’t have this already set-up and you are using the default bash terminal on Mac OS X, then you can add P4 to your path by doing the following:

  1. Open a Terminal window, (its in the utilities folder in the application folder).
  2. Type vi .bash_profile this will open the hidden file that defines your bash profile file in the vi text editor.
  3. Edit the line (press i to start editing and esc to stop) that starts with path=, insert the path to where you put p4 (in red) followed by a : right after path= e.g. PATH=”/Developer/Perforce/:…:${PATH}”.
  4. Save the file (with :s then enter) and then exit vi (with :q then enter).
  5. Quit Terminal.
  6. Reopen Terminal.
  7. Type p4 and hit enter, you should now get a response from the p4 application, although this will most likely get an error response unless you’ve already set-up your Perforce environment variables.

Now we can configure the three environment variables that the P4 application requires to work, these are $P4PORT, $P4USER and $P4CLIENT. These variables tell the P4 application how to connect to the server and the user to connect as and clientspec to connect with for that user. As I mentioned above the values of these three variables are the same as the perforce port, username and clientspec you used in P4V. To setup these environment variables we are going to add them to a hidden system file which is run every time you login to set-up the environment variables for your user profile (from this guide).

  1. Open a Terminal window.
  2. Type mkdir .MacOSX and hit enter to create the hidden directory the file resides in, the dot at the start means it is a hidden file.
  3. Type echo “” > .MacOSX/environment.plist and hit enter to create an empty file called environment.plist in your user directory directory, which is hidden.
  4. Type open .MacOSX/environment.plist and hit enter to open the file we just created in the plist editor.
  5. Add a child value with name P4PORT and the value from P4V e.g. localhost:1666.
  6. Add a sibling value with name P4USER with the value of your user from P4V e.g. daniel.
  7. Add a sibling value with name P4CLIENT with the value of the clientspec for your user in P4V e.g. daniels_clientspec.
  8. Save the file and exit the editor.
  9. Quit terminal.
  10. Logout and log back in.
  11. Open terminal and type P4 and hit enter, you should now get a non-error response from P4.

It is worth configuring the P4 command line application as it is the main way to administer a perforce server, so if you want add, delete or manage users, depots etc then you need to have P4 configured.

10 Nov 2008, 1:00am
Programming:
by

1 comment

Setting up Perforce Server (p4d) on Mac OS X

This morning I have been attempting to get p4d running on my intel iMac (running MacOS 10.5.5) so I can do some proper development at home.  I easily found the official Perforce guide to launching p4d at start-up with Launchd here, which seemed helpful and simple enough.  But it would seem I am now bogged down in file permission hell, which is something I don’t know allot about as I mainly work on Windows systems…

When I login I get the following message in my Console log and no p4d instance started:
“10/11/08 2:56:59 PM com.apple.launchctl.System[2] launchctl: Dubious ownership on file (skipping): /Library/LaunchDaemons/com.perforce.plist”
The permissions for the plist file are:
-rw-r–r–@ 1 Daniel  staff  700 10 Nov 11:58 /Library/LaunchDaemons/com.perforce.plist
And the permissions for p4 and p4d are:
-rwxr-xr-x@  1 Daniel  staff   580272 10 Nov 11:25 /Developer/Perforce/p4
-rwxr-xr-x@  1 Daniel  staff  1695008 10 Nov 11:25 /Developer/Perforce/p4d

The rest of the perforce files are set to:
-rw-r–r–  1 Daniel  staff   * 10 Nov 13:14 *

I used the example plist file from the perforce website and filled in the details specific for my installation:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Debug</key>
<false/>
<key>Label</key>
<string>com.perforce</string>
<key>OnDemand</key>
<false/>
<key>ProgramArguments</key>
<array>
<string>/Developer/Perforce/p4d</string>
</array>
<key>EnvironmentVariables</key>
<dict>
<key>P4LOG</key>
<string>/Developer/Perforce/p4log.log</string>
<key>P4PORT</key>
<string>1666</string>
<key>P4ROOT</key>
<string>/Developer/Perforce/p4root</string>
</dict>
<key>RunAtLoad</key>
<true/>
<key>ServiceDescription</key>
<string>Launches Perforce Server</string>
</dict>
</plist>

This plist file works if I use the following command:
launchctl unload /Library/LaunchDaemons/com.perforce.plist

Any help on resolving this would be greatly appreciated, I can start the server manaually for now but it would be great to have it running at start-up or login!  I’ve tried using the same plist file in the /Library/LaunchedAgents/ folder but I get the same results :(

Solution!

The following solution is from Perforce technical support, the owner and group of the plist file should be root:wheel which can be achieved by the following command:
sudo chown root:wheel /Library/LaunchDaemons/com.perforce.plist
The file should look like this after the change:
-rw-r–r–  1 root  wheel  797 11 Nov 11:01 com.perforce.plist