views:

41

answers:

4

I'm new to Perforce (but am fairly experienced with other systems, mostly SVN).
Now I'm trying to make a simple windows bat build script that needs to check in some build results (controversial to some, I know, but please try to ignore as it's a different discussion). I'm using p4 for this. The problem is that it seems I either:

  • Use the same "client" as on other machines (the -c option). This will have a "root", which looks like it specifies the absolute path where the working copy goes locally. Seems rather "wtf?" to me...
  • Interactively create a "client" for each machine (matching the local file system layout). The interactivity is obviously a deal-breaker for an automated script.

Can I somehow just use the current directory, like I can with SVN?
Is there a better option?

+1  A: 

You can interactively create a client without an editor by using p4 client -i:

The -i flag causes a client specification to be read from the standard input. The user's editor is not invoked

So in your builtscript you'd have a template for the client view, which you modify on the fly for the current build machine and pass it to p4 client -i.

jhwist
Thanks. I thought about that, but it would require string processing which would require either: 1. More batch script kung fu than I will ever develop, 2. A change of script language or 3. Use of more external tools.
Niklas
A: 

Apparently, you can pre-create a client workspace with a root directory of "null", which will cause perforce to use current working directory as root.

Niklas
That was my first thought, but don't you have to specify some path in the client space (mapping depot-paths to local paths)?
jhwist
+2  A: 

Create a workspace with a root of null and map the depot to that client. Here's an example client spec:

Client: client_name

Update: 2010/10/20 14:18:23

Access: 2010/10/20 14:20:53

Owner:  raven

Host:   ravens-pc

Description:
    Created by raven.

Root:   null

Options:    noallwrite noclobber nocompress unlocked modtime rmdir

SubmitOptions:  leaveunchanged

LineEnd:    local

View:
    //depot/... //client_name/...

The first thing your script should do is switch to this client by setting the $P4CLIENT$ environment variable:

p4 set p4client=client_name

You script will now be working in the context of that client. By virtue of the fact that you have specified a root of null, any syncing that you do will be relative to the current directory. So, if you sync //depot/foo/... while in C:\bar, your files will appear in C:\bar\foo.

The last thing your script should do is clear the P4CLIENT variable to restore the system to the default client specification:

p4 set p4client=

raven
Yes, this is essentially what I meant in my own answer. That aside, is there a difference in setting the environment variable and using -c client_name ?
Niklas
@Niklas: I don't know what you mean by "-c client_name". I take it you are referring to passing that switch to a command, but I can't figure out which one.
raven
Here it is: http://www.perforce.com/perforce/doc.current/manuals/cmdref/o.gopts.html#1040647
Niklas
@Niklas: Nice! I was not aware of that. By all means, screw the environment variable and use that -c switch.
raven
+1  A: 

I'd suggest creating a new client each time with a client template. First, manually create a client with the view as you'd like it in the actual build clients. Don't specify the Owner, Client, or Root fields. Then, each time you want a new client have it do the following:

p4 client -t my-client-template-name -o my-unique-client-name >clientspec.txt
p4 client -i <clientspec.txt

Where my-client-template-name is the client you created in the first step. Of course, when you're done be sure to do the following:

p4 client -d my-unique-client-name
Tim Clemons