FinalBuilder and Perforce

Hi All

Well I have recently moved from SVN to Perforce, and I am looking for similar bindings to:

IF[%Last_SVN_REVISION%]<>[%PREV_SVN_REVISION%]

Set Variable PREV_SVN_REVISION to [%Last_SVN_REVISION%]

 

I am not sure how to achieve this with Perforce as my CM.

 

Any ideas? 

Hi Ronan,

I’m assuming that you were using the Subversion Info command to read the current repository revision to LAST_SVN_REVISION?

As you’ve no doubt noticed, Perforce is a bit different because it doesn’t keep a global revision which is the same for every file. However, it does keep a folder revision which is updated whenever folder contents change, so the Folder Revision for //depot should be roughly equivalent.

Unfortunately, I can’t seem to find a p4.exe command (via Perforce Generic action) which outputs a folder history and/or revision. If you can find one, then you can parse the output using the OnStatusMessage event and set the last revision number that way. Let me know if you find a command, and I can suggest some script which may work for you.

Sorry I can’t be of more assistance.

Regards,

Angus

Sent off a support request to perforce, here is their response:

 

You can changelist numbers here as your revision history guides.  You can run
the "p4 changes -m1 //path..." against the path that you are wanting to build.
For example:

   p4 changes -m1 //depot/jphoto-0.3.6-src/...

Where "//depot/jphoto-0.3.6-src/..." is the location of the area that you are
monitoring in your build.

This will give you an output similar to the following:

   Change 317 on 2007/04/17 by timo@macbook 'updated USB interface'

Here you can see that it is change "317" was the last change made to files
beneath this depot path.  As a result I can use this as the starting point of
the revision history.  If I run the above command at a later date, and the
change returned is different, then I know I have to rebuild etc.

The other useful thing about this approach is that you can include the change
number within your build process.  Take the Perforce Server for example:

    Server version: XXXXXXXXXXXXXXXXXXXXX/113956

The "113956" part of the version string is actually the last changelist of the
codepath that this server was built with.  It means that just by including this
I know what code was used to build the server and using it, if needed, I can
make my workspace reflect this by running:

   p4 sync //...@113956

 

 

So I am going to try and get this working now.

Cheers

 

[Edit]

 

Hmmmm not as easy as I had hoped, I went down the route of using:

p4 changes -m1 //depot/jphoto-0.3.6-src/...

which obviously seems like the easiest way to interact. Any ideas on how to call this command using a script or similar?

 

 Cheers

 

Hi Ronan,

You can use the ‘Perforce Generic’ action to run the ‘changes’ command with the required parameters. Use the ‘OnStatusMessage’ event to parse the output and extract the number.

Let me know if you’d like me to mock up a project for you.

Regards,

Angus

I was looking through the help files, but couldn't find anything on:

OnStatusEvent

 

and how to use the events?

Hi Ronan,

There is some help on script events in the section “Action Script Events”, the online version is here:
https://www.finalbuilder.com/finalbuilder/Help/HTML/actionscriptevents.htm

hth.
.t8

Hi Ronan

The OnStatusMessage script event can be called muliple times, depending on how much output is captured from the executable being called. The statusmessage parameter is an object, which may contain multiple lines. You can check StatusMessage.Lines.Count to see how many lines there are, if there are more than 1 then use StatusMessage.Lines.Strings(index) to access each line, where index is 0 based. You should be able to use some VBScript or JavaScript to extract the change number from the output of P4. You can also use FinalBuilder variables in VBScript and JavaScript, either via the FBVariables object (in which case code completion will show you which variables are available) or just treat them as global variables in your script.

HTH


Cheers

The main issue I am having now (writing the script)

Basically the line I am getting back is:

Change 10110 on 2007/06/04 by ronanhayes@MW-RONANHAYES '#103281 - Tools.fbz5 Updated'

So it's a matter now of pulling out the correct version number which I would assume is:

#103281

as:

10110 is now the the changelist number. I could be wrong. So I simply need to extract the correct values from this line to save as a variable so I can compare with previous.

I'm not much up on VBScript and Java Script has been some time. Hopefully I can get it sorted, any extra help would be appreciated.

Cheers

 

[edit]

var s = "Change 10110 on 2007/06/04 by ronanhayes@MW-RONANHAYES '#103281 - Tools.fbz5 Updated'";
var m = s.match(/#\d+/);
alert(m);

 

Right all I need do now is:

 

var s = StatusMessage.Lines.Text

 

instead of an alert I just need to parse the text to a variable.

 

Any ideas? I'll keep going at it.

 

 

Hi Ronan,

Here's a simple solution in JScript which just extracts the first number preceded by a #. That should be robust enough to handle changes (ie I don't think every checkin has a changeset number, but I could be wrong...)

If you'd like a solution which matches the ChangeSet number as well, this can be arranged.

 

var line =  "Change 10110 on 2007/06/04 by ronanhayes@MW-RONANHAYES '#103281 - Tools.fbz5 Updated'";
var regexp = /#(\d+)\w/;

var matches = regexp.exec(line);
if (matches == null)
{
   throw "Failed to match changeset string on line : " + line;
}

var RevisionNo = matches[ 1] ;
Action.SendLogMessage("Folder revision " + RevisionNo);

 

- Angus

Hopefully one final thing, with

 

var line =

 

What should I be using in there when I want to take the the line returned by the Perforce Generic is it:

StatusMessage.Lines.Strings(0);

 

?

Hi Ronan,

That should work fine, as long as the command always puts the output on the first line (which I think it does.)

Regards,

Angus

Regarding variables how do I set them.

Is it via

Action.LogToVariable?

or is there an easier way to parse?

Hi Ronan,

You can just set variables as if they were local variables in the script, ie

VarName=VarValue;

… or you can use the FBVariables object, ie

FBVariables.VarName = VarValue;

(The FBVariables object gives you the advantage of code completion to show you the available names.)

- Angus

Cheers, that’s pretty much done it, just a issue getting the result from the Perforce Generic :

StatusMessage.Lines.Strings(0);

Is throwing an exception, from what I can gather StatusMessage.Lines.Strings(0) is often null due to the number of Status Messages that occur.

Even if I ignore the null VS2005 still prompts for the Exception. It’s somethign silly at this point

Hi Ronan,

Try the property StatusMessage.MessageText . That should never be null.

Regards,

Angus

Also, if the action sometimes output other messages (Apart from the one you want to test), remove the line

throw "Failed to match changeset string on line : " + line;

and replace it with just

return;

(this will ignore any lines which don’t match the change number, but it won’t tell you if it couldn’t find the change number.)

- Angus

I had adjusted the if statement to simply ignore the nulls

 

That said:

 

FBVariables.Last_Perforce_Revision = "2";

 

Doesn't seem to like being set. It's a tad strange but it throws and unknown exception.

Hi Ronan,

That looks like it should be OK. If you remove the FBVariables. notation, does it set the correct variable then?

If it’s still not working, could you please send us the project (support at finalbuilder dot com), and we’ll take a look at it. Thanks.

- Angus

It appears to have worked nicely, I will email the project if it fails building.

Thanks for all the help.

Ronan