Bug 375332: patcher2 changes required to support beta program; specifically, this allows a way to configure patcher to dump snippets for all a channel in a separate directory, to be staged separately. r=rhelmer.
authorpreed@mozilla.com
Tue, 17 Apr 2007 13:53:28 -0700
changeset 599 d5548d99e0ff510b276ea4a22960752e0043c19d
parent 598 c8818f341ad42599b0f4d1c76f20c7844893b0ef
child 600 1877b6827f1e85025e341c2440766e202e66c72f
push idunknown
push userunknown
push dateunknown
reviewersrhelmer
bugs375332
milestone1.9a4pre
Bug 375332: patcher2 changes required to support beta program; specifically, this allows a way to configure patcher to dump snippets for all a channel in a separate directory, to be staged separately. r=rhelmer.
tools/patcher/MozAUSConfig.pm
tools/patcher/MozAUSLib.pm
tools/patcher/patcher2.pl
--- a/tools/patcher/MozAUSConfig.pm
+++ b/tools/patcher/MozAUSConfig.pm
@@ -412,16 +412,24 @@ sub CreateUpdateGraph
         $u_config->{$u_key}->{'partial'} = $u_partial;
         $u_config->{$u_key}->{'complete'} = $u_complete;
         $u_config->{$u_key}->{'details'} = $u_details;
         $u_config->{$u_key}->{'license'} = $u_license;
         $u_config->{$u_key}->{'updateType'} = $u_updateType;
         $u_config->{$u_key}->{'force'} = $u_force;
         $u_config->{$u_key}->{'platforms'} = {};
 
+        # Add the keys that specify channel-specific snippet directories
+        foreach my $c (@channels) {
+            my $testKey = $c . '-dir';
+            if (exists($u->{$testKey})) {
+                $u_config->{$u_key}->{$testKey} = $u->{$testKey};
+            }
+        }
+
         my $r_config = $this->{'mAppConfig'}->{'release'};
         my @releases = keys %$r_config;
 
         # Find the set of locales that intersect for each platform by calculating how many times they appear.
 
         my $locale_intersection = {};
 
         for my $side ('from', 'to') {
--- a/tools/patcher/MozAUSLib.pm
+++ b/tools/patcher/MozAUSLib.pm
@@ -54,29 +54,31 @@ use MozBuild::Util qw(RunShellCommand Mk
 require Exporter;
 
 @ISA = qw(Exporter);
 @EXPORT_OK = qw(CreatePartialMarFile CreatePartialMarPatchInfo
                 GetAUS2PlatformStrings GetBouncerPlatformStrings
                 ValidateToolsDirectory
                 EnsureDeliverablesDir
                 SubstitutePath
+                GetSnippetDirFromChannel
                );
 
 use strict;
 
 ##
 ## CONSTANTS 
 ##
 
 use vars qw($MAR_BIN $MBSDIFF_BIN $MAKE_BIN
             $INCREMENTAL_UPDATE_BIN $UNWRAP_FULL_UPDATE_BIN
             $TMPDIR_PREFIX 
             %BOUNCER_PLATFORMS %AUS2_PLATFORMS
-            $DEFAULT_PARTIAL_MAR_OUTPUT_FILE);
+            $DEFAULT_PARTIAL_MAR_OUTPUT_FILE
+            $DEFAULT_SNIPPET_BASE_DIR $DEFAULT_SNIPPET_TEST_DIR);
 
 $MAR_BIN = 'dist/host/bin/mar';
 $MBSDIFF_BIN = 'dist/host/bin/mbsdiff';
 
 $INCREMENTAL_UPDATE_BIN = 'tools/update-packaging/make_incremental_update.sh';
 $UNWRAP_FULL_UPDATE_BIN = 'tools/update-packaging/unwrap_full_update.pl';
 
 $MAKE_BIN = '/usr/bin/make';
@@ -90,16 +92,19 @@ use vars qw($MAR_BIN $MBSDIFF_BIN $MAKE_
 
 %AUS2_PLATFORMS = ( 'macppc' => 'Darwin_ppc-gcc3',
                     'mac' => 'Darwin_Universal-gcc3',
                     'linux-i686' => 'Linux_x86-gcc3',
                     'win32' => 'WINNT_x86-msvc' );
 
 $DEFAULT_PARTIAL_MAR_OUTPUT_FILE = 'partial.mar';
 
+$DEFAULT_SNIPPET_BASE_DIR = 'aus2';
+$DEFAULT_SNIPPET_TEST_DIR = $DEFAULT_SNIPPET_BASE_DIR . '.test';
+
 sub EnsureDeliverablesDir
 {
    my %args = @_;
 
    die "ASSERT: null config spec\n" if (not defined($args{'config'}));
    my $configSpec = $args{'config'};
 
    my $fullDeliverableDirPath = catfile($configSpec->GetDeliverableDir(),
@@ -312,9 +317,34 @@ sub SubstitutePath
     $string =~ s/%locale%/$locale/g;
     $string =~ s/%bouncer\-platform%/$bouncer_platform/g;
     $string =~ s/%version%/$version/g;
     $string =~ s/%app%/$app/g;
 
     return $string;
 }
 
+sub GetSnippetDirFromChannel {
+    my %args = @_;
+    die 'ASSERT: GetSnippetDirFromChannel(): null/invalid update config ' .
+     "object\n" if (!exists($args{'config'}) || ref($args{'config'}) ne 'HASH');
+    die "ASSERT: GetSnippetDirFromChannel(): null channel\n" if (
+     !exists($args{'channel'}));  
+
+    my $channel = $args{'channel'};
+    my $currentUpdateConfig = $args{'config'};
+
+    die "ASSERT: GetSnippetDirFromChannel(): invalid update config object\n"
+     if (! exists($currentUpdateConfig->{'to'}) || 
+     !exists($currentUpdateConfig->{'from'}));
+
+    my $snippetDirTestKey = $channel . '-dir';
+  
+    if (exists($currentUpdateConfig->{$snippetDirTestKey})) {
+        return $DEFAULT_SNIPPET_BASE_DIR . '.' . 
+         $currentUpdateConfig->{$snippetDirTestKey};
+    } elsif ($channel =~ /test(-\w+)?$/) {
+        return $DEFAULT_SNIPPET_TEST_DIR;
+    } else {
+        return $DEFAULT_SNIPPET_BASE_DIR;
+    }
+}
 1;
--- a/tools/patcher/patcher2.pl
+++ b/tools/patcher/patcher2.pl
@@ -46,51 +46,49 @@ use Getopt::Long;
 use Data::Dumper;
 use Cwd;
 use English;
 use IO::Handle;
 
 use File::Path;
 use File::Copy qw(move copy);
 use File::Spec::Functions;
+use File::Basename;
 
 use MozAUSConfig;
 use MozAUSLib qw(CreatePartialMarFile
                  GetAUS2PlatformStrings
                  EnsureDeliverablesDir
-                 ValidateToolsDirectory SubstitutePath);
+                 ValidateToolsDirectory SubstitutePath
+                 GetSnippetDirFromChannel);
 
 use MozBuild::Util qw(MkdirWithPath RunShellCommand DownloadFile HashFile);
 
 $Data::Dumper::Indent = 1;
 
 autoflush STDOUT 1;
 autoflush STDERR 1;
 
 ##
 ## CONSTANTS
 ##
 
 use vars qw($PID_FILE
             $DEFAULT_HASH_TYPE
             $DEFAULT_CVSROOT
             $DEFAULT_SCHEMA_VERSION $CURRENT_SCHEMA_VERSION
-            $SNIPPET_DIR $SNIPPET_TEST_DIR
             $ST_SIZE );
 
 $PID_FILE = 'patcher2.pid';
 $DEFAULT_HASH_TYPE = 'SHA1';
 $DEFAULT_CVSROOT = ':pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot';
 
 $DEFAULT_SCHEMA_VERSION = 0;
 $CURRENT_SCHEMA_VERSION = 1;
 
-$SNIPPET_DIR = 'aus2';
-$SNIPPET_TEST_DIR = $SNIPPET_DIR . '.test';
-
 $ST_SIZE = 7;
 
 sub main {
     Startup();
 
     my (%args, %move_args);
     my $config = new MozAUSConfig();
 
@@ -673,17 +671,20 @@ sub CreateCompletePatchinfo {
                      path => $u_config->{$u}->{'license'},
                      locale => $l,
                      version => $to->{'appv'});
                 }
 
                 my $updateType = $config->GetCurrentUpdate()->{'updateType'};
 
                 for my $c (@channels) {
-                    my $aus_prefix = catfile($u, $SNIPPET_DIR, 
+                    my $snippetDir = GetSnippetDirFromChannel(
+                     config => $config->GetCurrentUpdate(), channel => $c);
+
+                    my $aus_prefix = catfile($u, $snippetDir, 
                                              $from_aus_app,
                                              $from_aus_version,
                                              $from_aus_platform,
                                              $from_aus_buildid,
                                              $l, $c);
 
                     my $complete_patch = $ul_config->{$l}->{'complete_patch'};
                     $complete_patch->{'info_path'} = catfile($aus_prefix,
@@ -739,18 +740,21 @@ sub CreateCompletePatchinfo {
                         my $testPatch = {};
                         foreach my $key (keys(%{$complete_patch})) {
                             $testPatch->{$key} = $complete_patch->{$key};
                         }
 
                         foreach my $testChan (split(/[\s,]+/, 
                          $u_config->{$u}->{'testchannel'})) {
 
+                            my $snippetDir = GetSnippetDirFromChannel(
+                             config => $u_config->{$u}, channel => $testChan);
+
                             $testPatch->{'info_path'} = catfile($u,
-                             'aus2.test', $from_aus_app, 
+                             $snippetDir, $from_aus_app, 
                              $from_aus_version, $from_aus_platform, 
                              $from_aus_buildid, $l, $testChan, 'complete.txt');
 
                             my $testUrlKey = $testChan . '-url';
 
                             if (exists($complete->{$testUrlKey})) {
                                 $testPatch->{'url'} = SubstitutePath(
                                  path => $complete->{$testUrlKey},
@@ -886,19 +890,19 @@ sub CreatePastReleasePatchinfo {
                      path => $config->GetCurrentUpdate()->{'license'},
                      locale => $locale,
                      version => $patchLocaleNode->{'appv'});
                 }
 
                 my $updateType = $config->GetCurrentUpdate()->{'updateType'};
 
                 foreach my $channel (@{$pastUpd->{'channels'}}) {
-                    my $ausDir = ($channel =~ /test(-\w+)?$/) 
-                     ? $SNIPPET_TEST_DIR : $SNIPPET_DIR;
-
+                    my $ausDir = GetSnippetDirFromChannel(config => 
+                     $config->GetCurrentUpdate(), channel => $channel);
+                    
                      my $ausPrefix = catfile($prefixStr, $ausDir, $fromAusApp,
                                              $fromAusVersion, $fromAusPlatform,
                                              $fromAusBuildId, $locale,
                                              $channel);
 
                     my $completePatch = {};
                     $completePatch ->{'info_path'} = catfile($ausPrefix,
                                                              'complete.txt');
@@ -1048,17 +1052,20 @@ sub CreatePartialPatchinfo {
                      path => $u_config->{$u}->{'license'},
                      locale => $l,
                      version => $to->{'appv'});
                 }
 
                 my $updateType = $u_config->{$u}->{'updateType'};
 
                 for my $c (@channels) {
-                    my $aus_prefix = catfile($u, $SNIPPET_DIR, 
+                    my $snippetDir = GetSnippetDirFromChannel(config =>
+                     $u_config->{$u}, channel => $c);
+
+                    my $aus_prefix = catfile($u, $snippetDir,
                                              $from_aus_app,
                                              $from_aus_version,
                                              $from_aus_platform,
                                              $from_aus_buildid,
                                              $l,
                                              $c);
 
                     my $partial_patch = $ul_config->{$l}->{'partial_patch'};
@@ -1113,18 +1120,21 @@ sub CreatePartialPatchinfo {
                         my $testPatch = {};
                         foreach my $key (keys(%{$partial_patch})) {
                             $testPatch->{$key} = $partial_patch->{$key};
                         }
 
                         foreach my $testChan (split(/[\s,]+/, 
                          $u_config->{$u}->{'testchannel'})) {
 
+                            my $snippetDir = GetSnippetDirFromChannel(config =>
+                             $u_config->{$u}, channel => $testChan);
+
                             $testPatch->{'info_path'} = catfile($u,
-                             'aus2.test', $from_aus_app,
+                             $snippetDir, $from_aus_app,
                              $from_aus_version, $from_aus_platform,
                              $from_aus_buildid, $l, $testChan, 'partial.txt');
 
                             my $testChanKey = $testChan . '-url';
 
                             if (exists($partial->{$testChanKey})) {
                                 $testPatch->{'url'} = SubstitutePath(
                                  path => $partial->{$testChanKey},
@@ -1157,18 +1167,17 @@ sub CreatePartialPatchinfo {
 
 sub write_patch_info {
     my %args = @_;
 
     my $patch = $args{'patch'};
     my $schemaVersion = $args{'schemaVer'} || $DEFAULT_SCHEMA_VERSION;
 
     my $info_path = $patch->{'info_path'};
-    $info_path =~ m/^(.*)\/[^\/]*$/;
-    my $info_path_parent = $1;
+    my $info_path_parent = dirname($patch->{'info_path'});
     my $text;
 
     if ($DEFAULT_SCHEMA_VERSION == $schemaVersion) {
         $text  = "$patch->{'type'}\n";
         $text .= "$patch->{'url'}\n";
         $text .= "$patch->{'hash_type'}\n";
 
         $text .= "$patch->{'hash_value'}\n";