pass build ID to FTP for use by PatcherConfig b=387970 r=preed
authorrhelmer@mozilla.com
Tue, 14 Aug 2007 16:53:34 -0700
changeset 4646 930bb2fac8f69cb65ae716385cd77a0da20cb8ce
parent 4645 a9ede06c12528be69d9290f4b4dd9587f8198274
child 4647 977e76b3b5f2675a8784cfe23939db8110469f1b
push idunknown
push userunknown
push dateunknown
reviewerspreed
bugs387970
milestone1.9a8pre
pass build ID to FTP for use by PatcherConfig b=387970 r=preed
tools/release/Bootstrap/Step/Build.pm
tools/release/Bootstrap/Step/PatcherConfig.pm
tools/release/MozBuild/TinderLogParse.pm
--- a/tools/release/Bootstrap/Step/Build.pm
+++ b/tools/release/Bootstrap/Step/Build.pm
@@ -1,13 +1,15 @@
 #
 # Build step. Calls tinderbox to produce en-US Firefox build.
 #
 package Bootstrap::Step::Build;
 
+use File::Temp qw(tempfile);
+
 use Bootstrap::Step;
 
 @ISA = ("Bootstrap::Step");
 
 sub Execute {
     my $this = shift;
 
     my $config = new Bootstrap::Config();
@@ -32,16 +34,17 @@ sub Execute {
       cmdArgs => ['--once', '--mozconfig', 'mozconfig', '--depend', 
                   '--config-cvsup-dir', 
                   catfile($buildDir, 'tinderbox-configs')],
       dir => $buildDir,
       logFile => $buildLog,
       timeout => 36000
     );
 
+    $this->StoreBuildID();
 }
 
 sub Verify {
     my $this = shift;
 
     my $config = new Bootstrap::Config();
     my $buildDir = $config->Get(sysvar => 'buildDir');
     my $productTag = $config->Get(var => 'productTag');
@@ -89,21 +92,23 @@ sub Push {
     if (! defined($pushDir)) {
         die("No pushDir found in $buildLog");
     }
     $pushDir =~ s!^http://ftp.mozilla.org/pub/mozilla.org!/home/ftp/pub!;
 
     my $candidateDir = $config->GetFtpCandidateDir(bitsUnsigned => 1);
 
     my $osFileMatch = $config->SystemInfo(var => 'osname');    
+
+    # TODO - use a more generic function for this kind of remapping
     if ($osFileMatch eq 'win32')  {
       $osFileMatch = 'win';
     } elsif ($osFileMatch eq 'macosx') {
       $osFileMatch = 'mac';
-    }    
+    }
 
     $this->Shell(
       cmd => 'ssh',
       cmdArgs => ['-2', '-l', $sshUser, $sshServer,
                   'mkdir -p ' . $candidateDir],
       logFile => $pushLog,
     );
 
@@ -146,10 +151,60 @@ sub Announce {
     } 
 
     $this->SendAnnouncement(
       subject => "$product $version build step finished",
       message => "$product $version en-US build was copied to the candidates dir.\nBuild ID is $buildID\nPush Dir was $pushDir",
     );
 }
 
+sub StoreBuildID() {
+    my $this = shift;
+
+    my $config = new Bootstrap::Config();
+    my $productTag = $config->Get(var => 'productTag');
+    my $rc = $config->Get(var => 'rc');
+    my $logDir = $config->Get(var => 'logDir');
+    my $sshUser = $config->Get(var => 'sshUser');
+    my $sshServer = $config->Get(var => 'sshServer');
+
+    my $rcTag = $productTag . '_RC' . $rc;
+    my $buildLog = catfile($logDir, 'build_' . $rcTag . '-build.log');
+    my $pushLog  = catfile($logDir, 'build_' . $rcTag . '-push.log');
+
+    my $logParser = new MozBuild::TinderLogParse(
+        logFile => $buildLog,
+    );
+    my $pushDir = $logParser->GetPushDir();
+    if (! defined($pushDir)) {
+        die("No pushDir found in $buildLog");
+    }
+    $pushDir =~ s!^http://ftp.mozilla.org/pub/mozilla.org!/home/ftp/pub!;
+
+    # drop os-specific buildID file on FTP
+    my $buildID = $logParser->GetBuildID();
+    if (! defined($buildID)) {
+        die("No buildID found in $buildLog");
+    }
+    if (! $buildID =~ /^\d+$/) {
+        die("ASSERT: Build: build ID is not numerical: $buildID")
+    }
+
+
+    my $osFileMatch = $config->SystemInfo(var => 'osname');    
+
+    my ($bh, $buildIDTempFile) = tempfile(DIR => '.');
+    print $bh 'buildID=' . $buildID;
+    $bh->close() || 
+     die("Could not open buildID temp file $buildIDTempFile: $!");
+
+    my $buildIDFile = $osFileMatch . '_info.txt';
+    $this->Shell(
+      cmd => 'scp',
+      cmdArgs => [$buildIDTempFile, 
+                  $sshUser . '@' . $sshServer . ':' .
+                  $pushDir . '/' . $buildIDFile],
+      logFile => $pushLog,
+    );
+}
+
 1;
 
--- a/tools/release/Bootstrap/Step/PatcherConfig.pm
+++ b/tools/release/Bootstrap/Step/PatcherConfig.pm
@@ -1,15 +1,16 @@
 #
 # Updates step. Configures patcher files.
 # 
 # 
 package Bootstrap::Step::PatcherConfig;
 
 use Config::General;
+use File::Temp qw(tempfile);
 
 use MozBuild::Util qw(MkdirWithPath);
 
 use Bootstrap::Step;
 use Bootstrap::Config;
 use Bootstrap::Util qw(CvsCatfile GetBouncerPlatforms
                        GetBouncerToPatcherPlatformMap);
 
@@ -78,16 +79,19 @@ sub BumpPatcherConfig {
     my $product = $config->Get(var => 'product');
     my $configBumpDir = $config->Get(var => 'configBumpDir');
     my $version = $config->Get(var => 'version');
     my $oldVersion = $config->Get(var => 'oldVersion');
     my $rc = $config->Get(var => 'rc');
     my $oldRc = $config->Get(var => 'oldRc');
     my $localeInfo = $config->GetLocaleInfo();
     my $patcherConfig = $config->Get(var => 'patcherConfig');
+    my $sshUser = $config->Get(var => 'sshUser');
+    my $sshServer = $config->Get(var => 'sshServer');
+    my $logDir = $config->Get(var => 'logDir');
 
     # First, parse the file.
     my $checkedOutPatcherConfig = catfile($configBumpDir, 'patcher', 
      $patcherConfig);
 
     my $patcherConfigObj = new Config::General(-ConfigFile => 
      $checkedOutPatcherConfig);
 
@@ -191,21 +195,60 @@ sub BumpPatcherConfig {
     # Now, add the new <release> stanza for the release we're working on
 
     my $releaseObj;
     $appObj->{'release'}->{$version} = $releaseObj = {};
 
     $releaseObj->{'schema'} = '1';
     $releaseObj->{'version'} = $releaseObj->{'extension-version'} = $version;
 
-    ## XXX - Dummy data for now...
-    my $linBuildId = '1234567890';
-    my $winBuildId = '1234567891';
-    my $macBuildId = '1234567892';
-    
+    my $linBuildId;
+    my $winBuildId;
+    my $macBuildId;
+
+    # grab os-specific buildID file on FTP
+    my $candidateDir = $config->GetFtpCandidateDir(bitsUnsigned => 0);
+    foreach my $os ('linux', 'macosx', 'win32') {
+        my ($bh, $buildIDTempFile) = tempfile(DIR => '.');
+        $bh->close();
+        $this->Shell(
+          cmd => 'scp',
+          cmdArgs => [$sshUser . '@' . $sshServer . ':' . 
+                      $candidateDir .'/' . $os . '_info.txt',
+                      $buildIDTempFile],
+        );
+        my $buildID;
+        open(FILE, "< $buildIDTempFile") || 
+         die("Could not open buildID temp file $buildIDTempFile: $!");
+        while (<FILE>) {
+          my ($var, $value) = split(/\s*=\s*/, $_, 2);
+          if ($var eq 'buildID') {
+              $buildID = $value;
+          }
+        }
+        close(FILE) || 
+         die("Could not close buildID temp file $buildIDTempFile: $!");
+        if (! defined($buildID)) {
+            die("Could not read buildID from temp file $buildIDTempFile: $!");
+        }
+        if (! $buildID =~ /^\d+$/) {
+            die("ASSERT: BumpPatcherConfig: $buildID is non-numerical");
+        }
+        chomp($buildID);
+        if ($os eq 'linux') {
+            $linBuildId = "$buildID";
+        } elsif ($os eq 'macosx') {
+            $macBuildId = "$buildID";
+        } elsif ($os eq 'win32') {
+            $winBuildId = "$buildID";
+        } else {
+            die("ASSERT: BumpPatcherConfig(): unknown OS $os");
+        }
+    }
+
     $releaseObj->{'platforms'} = { 'linux-i686' => $linBuildId,
                                    'win32' => $winBuildId,
                                    'mac' => $macBuildId };
 
     $releaseObj->{'locales'} = join(' ', sort (keys(%{$localeInfo})));
 
     $releaseObj->{'completemarurl'} = 
      'http://stage.mozilla.org/pub/mozilla.org/' . $product. '/nightly/' .
--- a/tools/release/MozBuild/TinderLogParse.pm
+++ b/tools/release/MozBuild/TinderLogParse.pm
@@ -40,23 +40,31 @@ sub GetBuildID {
     while (<FILE>) {
         if ($_ =~ /$searchString/) {
             $buildID = $_;
  
             # remove search string
             $buildID =~ s/$searchString//;
 
             # remove trailing slash
-            $buildID =~ s/^\.//;
+            $buildID =~ s/\.$//;
             last;
         }
     }
 
     close FILE or die("Cannot close file $log: $!");
 
+    if (! defined($buildID)) {
+        return undef;
+    }
+    if (! $buildID =~ /^\d+$/) {
+        die("ASSERT: Build: build ID is not numerical: $buildID")
+    }
+
+    chomp($buildID);
     return $buildID;
 }
 
 ## 
 # GetPushDir - attempts to find the directory Tinderbox pushed to build to
 #
 # Searches for a string of the form:
 #  Linux Firefox Build available at: 
@@ -81,18 +89,24 @@ sub GetPushDir {
             last;
         }
         if ($_ =~ /$searchString/) {
             $found = 1;
         }
     }
 
     close FILE or die("Cannot close file $log: $!");
+ 
+    if (! defined($pushDir)) {
+        return undef;
+    }
 
     chomp($pushDir);
+    # remove empty space at end of URL
+    $pushDir =~ s/\s+$//;
 
     return $pushDir;
 }
 
 sub GetLogFileName {
     my $this = shift;
     my %args = @_;