FAQ for integrating Perforce with your build scripts

Contributed by Jeff Bowles

Note - the intended audience for this FAQ is a shell/perl hacker who writes or maintains local build scripts and wants to integrate Perforce into them.

    Labels
  1. How do I create a label? What should I include in a label?
  2. If I want to create a new label for each overnight build, how would I do it?
  3. Should I use labels or change numbers to track the contents of overnight builds?
  4. So the release needs to be remade three months after it went out. What do I do?
  5. I like this overnight build and want to officially designate it as a "release" build. What should I do?
  6. I need to create a release build - what's different in that process?
  7. Clients
  8. How do I populate the build area from a nightly build script? What are the problems that will come up?
  9.  Updating depot files from a script
  10. How do I update the depot to include a new log, or to include a new line in a logfile?
  11. Should l check in my log files? What files might need to be modified and checked in as part of a build?
  12. Putting a release out
  13. What should I back up when I put a release out?
  14. How do I make an "escrow" copy of the files (that built the release) for the off-site vaults?

  1. How do I create a build label? What should I include in a label?

  2. If I want to create a new label for each overnight build, how would I do it?

  3.  
    1. Make sure you're using a regular name for the label, e.g. "bld_xxx_yyy" where "xxx" is the codeline name and "yyy" is a counter.
    2. Create the first label in the sequence, which would be "bld_xxx_1". See the previous question for that.
    3. In the Unix shell, you would do the following (cut and paste):
    4.    CodeLineName=xxx
         LabelSpec=tst_${CodeLineName}_
         toplabelnumber=`p4 labels | grep $LabelSpec | sed "s/^Label $LabelSpec//" | \
              sed "s/ .*//" | sort -r -n | head -1`
         # at this point, we know the most recent label in this codeline and just need
         # to create a new label and populate it.
         TopLabel=$LabelSpec$toplabelnumber
         echo Current Label is $LabelSpec$toplabelnumber
         if [ "$toplabelnumber" != "" ]
         then
              newlabelnumber=`expr $toplabelnumber + 1`
              NewLabel=$LabelSpec$newlabelnumber
              echo "New Label is $NewLabel"
       
              # the following two commands are from the previous FAQ item.
              p4 label -o -t $TopLabel $NewLabel | p4 label -i
              p4 labelsync -l $NewLabel //depot/...
              # It's best to obsolete labels that are kinda of old, so we
              # do it here.
              if [ "$toplabelnumber" -gt 10 ]
              then
                      obsoletelabelnumber=`expr $toplabelnumber - 10`
                      ObsoleteLabel=$LabelSpec$obsoletelabelnumber
                      p4 label -d $ObsoleteLabel
              fi
         else
              echo "There was no label to match!" 1>&2
              exit 1
         fi
       

    5. Perl hackers will look at the previous "Bourne shell" example and use it as an example of why you don't want to do string processing in "Bourne shell". One perl treatment of this follows: 
    6.    $CodeLineName = "xxx";
         $LabelSpec="tst_" . $CodeLineName . "_";

         @AllLabels = `p4 labels`;
         @ThisCodeLineLabels = sort(sortrevlabel grep(/$LabelSpec/, @AllLabels));
         $TopLabelLine = $ThisCodeLineLabels[0];
         $TopLabel = $1 if ($TopLabelLine =~ /^Label\s(\S+)\s/);
         $TopLabelNumber = $1 if ($TopLabel =~ /^\S+_(\d+)$/);

         print "The last label in this codeline is $TopLabel\n";
         $NewLabelNumber = $TopLabelNumber + 1;
         $NewLabel = "$LabelSpec$NewLabelNumber";
         print "New Label is $NewLabel\n";
         system("p4 label -o -t $TopLabel $NewLabel | p4 label -i");   # in real life, return code would be checked!
         system("p4 labelsync -l $NewLabel //depot/...");
         if ($TopLabelNumber > 10 )
         {
              $ObsoleteLabelNumber = $TopLabelNumber - 10;
              $ObsoleteLabel = "$LabelSpec$ObsoleteLabelNumber";
              system("p4 label -d $ObsoleteLabel");
         }

         sub sortrevlabel {
              my($labelnum_a, $labelnum_b) = ();
              $labelnum_a = $1 if ($a =~ /.*_(\d+)/);
              $labelnum_b = $1 if ($b =~ /.*_(\d+)/);
              return ($labelnum_b <=> $labelnum_a);
              }

    7. The underlined part in the above fragments probably should have a "sed" command between the two 'p4 label' commands, to change the description for each label.

  4. Should I use labels or change numbers to track the contents of overnight builds?

  5.  
  6. So the release needs to be remade three months after it went out. What do I do?
  7. You'll need a slightly-hacked version of your "get the source and do a build" script. The hacks are:
    • It shouldn't use or touch any labels except for the release label you've remembered to create when you made the release. Delete the lines in the script that create labels or run "p4 labelsync" on them.
    • Change the line in the script that does the "p4 sync -f  ...#have" so that it looks like:
    •    p4 sync -f  //depot/xxx/...@labelname

      where "xxx" is the name of the codeline, and "labelname" is the release label.

    • Bug your system administrators about whether compiler versions, OS releases, etc, have changed since the release was created. Listen carefully to their answers.
    • Run the script. It should create the original release faithfully, although most compilers embed timestamps within the .exe and .obj files, so you might not have byte-for-byte identical files.
    • Rerun your regressions to gain confidence in the newly-built product.

  8. I like this overnight build and want to officially designate it as a "release" build. What should I do?
  9. See the previous step - you just need to run "p4 label" (to create a label) and then "p4 labelsync" to the overnight label or change number that created the build:

       p4 labelsync -l release_label_name  //depot/xxx/...@bld_xxx_23

    or

       p4 labelsync -l release_label_name  //depot/xxx/...@12345

    The first case is for "overnight build #23 for codeline xxx", if you're using that convention for overnight builds; the second case is if you use change numbers to track the overnight build contents.
     


  10. I need to create a release build - what's different in that process?

  11.  
    This depends on what packages the release for deployment. If you use the same build mechanisms for overnight and release builds, you should only need to do a few steps:
    • Run the overnight build script to create the build.
    • Label the build area that created the release, using "p4 label" and then "p4 labelsync". Pick the 'view' for the label carefully, so that it doesn't include parts of the depot not included in this release.
    • Run "p4 label" a second time on the new label, and change the status of the label to "locked" so that "p4 labelsync" cannot be run against it accidently.
     

  12. How do I populate the build area for an overnight build? What are the problems that will come up?

  13.  
  14. How do I update the depot to include a new log, or to include a new line in a logfile?

  15.  
  16. Should l check in my log files? What files might need to be modified and checked in as part of a build?

  17.  
  18. What should I back up when I put a release out?

  19.  
     
  20. How do I make an "escrow" copy of the files (that built the release) for the off-site vaults?

  21.  
    You can use a label to create an initial fileset that you'll archive. It's pretty easy:
Last modified on 7 November 2003.