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.
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:
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.
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.
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.
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; }