18
votes

I am writing a script to build all our projects on a Ubuntu build machine.

Each project is stored in Perforce and I am using p4 to perform the above.

The command I am using is:

p4 -u <MyUsername> -P <MyPassword> client MyWorkspace

This runs and loads vim which I then need to perform a :wq [Enter] to quit from.

Can I auto-save or avoid vim loading?

9
Just wanted to point out that this box is used via SSH from a remote location on our network. - neildeadman
I applaud the idea, but have you looked into using a continuous integration application? Hudson and/or Jenkins is one we use, and it works fairly well with Perforce. - Caleb Huitt - cjhuitt

9 Answers

21
votes

For my builds I have a text file, which I have in perforce, containing my client. That way I know what the client looked like at that build (I don't use a spec depot).

So on unix machines:

$ cat client.txt | p4 client -i

or for windows:

type client.txt | p4 client -i

creates the client from the txt file in perforce. You can create the text by doing a p4 client -o <client_name> >client.txt and change it from there.

10
votes

You probably want to try p4 client -i. From the help page:

The -i flag reads a client specification from the standard input. The user's editor is not invoked.

So you construct your client-spec in a script and pass it to p4 client -i. Additionally, -t could be helpful, too:

The -t flag constructs the client view by using the specified client's view and options as a template, instead of using the existing view or creating a new default view.

5
votes

I use heredocs to minimize the need for temporary files

export P4CLIENT=tmp_$$
p4 client -i <<HERE
Client: ${P4CLIENT}
Root: /tmp/${P4CLIENT}
Stream: //OurStreamDepot/${branch}
HERE

You only need to specify the Client:, Root: and Stream: fields (or View: if you are using the older //depot style)

3
votes

You don't need to create a new client for each build. You can re-use the same client, just run 'p4 sync' to update the filesystem with the current version of the code to build.

1
votes

I absolutely agree with Byran's answer. You do you need to create a unique client for every time you want to do a build. There is no issue with having multiple projects using the same workspace; you only need to have create multiple workspaces if you want to run builds in parallel on the same machine. Creating a new workspace and performing a full sync each build will significantly increase your build times.

If you need to ensure that you have a clean workspace configure your intermediate and output paths to point to a common location high up in the folder hierarchy.

Root
 /Bin
 /Intermediate
 /Source

This way you only need to delete those two directories and perform p4 sync //filespec/ to do a clean build.

1
votes

I'm not completely sure I understand what you are trying to do, but if you want to keep using the same client, either set your variable P4CLIENT=MyWorkspace or use

p4 -u <MyUsername> -P <MyPassword> -c MyWorkspace.

0
votes

If you would like to keep the entire process inside perforce make a template workspace / client called client_template and pipe it in

p4 client -o -t client_template new_client|p4 client -i
0
votes

Simply run the command 'p4 client' after 'p4 login'. It will ask for all the details after running the command. you just fill those details as per your requirement.

Mainly, You need to only focus on two parameters in the temp file. As soon as you save the file, the client would be created.

Root: This is the local repository path. for example,
Root: /User/codebase/code

View: stream you want to map to remote depot from your client. for example,
View: //exp/main/... //expbuild_centos/...

[root@no1011142063123 ~]# p4 client "expbuild_centos"
Client expbuild_centos saved.
[root@no1011142036123 ~]#  
-1
votes

A different approach, assuming you are in the working directory of your client workspace:

echo "P4CLIENT=MyWorkspace" > .perforce
export P4EDITOR=true`

and then

p4 client

will either create the workspace if it is new one, or mention something like:

Client MyWorkspace not changed.