Bug 1387241 - Reland the LZMA and SHA384 mar generation scripts from Bug 1385780 after 56 Beta 3. r=bhearsum, a=lhenry
authorRobert Strong <robert.bugzilla@gmail.com>
Thu, 17 Aug 2017 10:37:03 -0700
changeset 423605 a0f80f524721018a1d57483eb419ebe01cca99cc
parent 423604 84b06813d694b1b0e29b462bdbe27c3481b9d5bf
child 423606 5ffaf610754fda9ed6ab708fba70b5cf84050044
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbhearsum, lhenry
bugs1387241, 1385780
milestone56.0
Bug 1387241 - Reland the LZMA and SHA384 mar generation scripts from Bug 1385780 after 56 Beta 3. r=bhearsum, a=lhenry Adds support to unwrap_full_update.pl to detect if the mar file's contents were compressed using bzip2 and if not to default to lzma.
tools/update-packaging/unwrap_full_update.pl
--- a/tools/update-packaging/unwrap_full_update.pl
+++ b/tools/update-packaging/unwrap_full_update.pl
@@ -7,39 +7,53 @@
 # This tool unpacks a full update package generated by make_full_update.sh
 # Author: Benjamin Smedberg
 #
 
 # -----------------------------------------------------------------------------
 # By default just assume that these tools exist on our path
 
 use Getopt::Std;
+use Cwd 'abs_path';
 
 my ($MAR, $XZ, $BZIP2, $MAR_OLD_FORMAT, $archive, @marentries, @marfiles);
 
 if (defined($ENV{"MAR"})) {
     $MAR = $ENV{"MAR"};
 }
 else {
     $MAR = "mar";
 }
 
-if (defined($ENV{"MAR_OLD_FORMAT"})) {
-    $MAR_OLD_FORMAT = 1;
-    if (defined($ENV{"BZIP2"})) {
-        $BZIP2 = $ENV{"BZIP2"};
-    }
-    else {
-        $BZIP2 = "bzip2";
-    }
+if (defined($ENV{"BZIP2"})) {
+    $BZIP2 = $ENV{"BZIP2"};
+}
+else {
+    $BZIP2 = "bzip2";
+}
+
+if (defined($ENV{"XZ"})) {
+    $XZ = $ENV{"XZ"};
 }
 else {
-    $MAR_OLD_FORMAT = 0;
-    if (defined($ENV{"XZ"})) {
-        $XZ = $ENV{"XZ"};
+    if (system("xz --version > /dev/null 2>&1") != 0) {
+        # Some of the Windows build systems have xz.exe in topsrcdir/xz/.
+        my $xzwinpath = abs_path(__FILE__);
+        $xzwinpath = substr($xzwinpath, 0, rindex($xzwinpath, '/'));
+        $xzwinpath = substr($xzwinpath, 0, rindex($xzwinpath, '/'));
+        $xzwinpath = substr($xzwinpath, 0, rindex($xzwinpath, '/'));
+        $xzwinpath = $xzwinpath . "/xz/xz.exe";
+        if (-e $xzwinpath) {
+            $XZ = $xzwinpath;
+        }
+        else {
+            # If the xz executable was not found fallback to trying to execute
+            # xz and follow the normal failure path if it isn't found.
+            $XZ = "xz";
+        }
     }
     else {
         $XZ = "xz";
     }
 }
 
 sub print_usage
 {
@@ -54,33 +68,50 @@ getopts("h", \%opts);
 
 if (defined($opts{'h'}) || scalar(@ARGV) != 1) {
     print_usage();
     exit 1;
 }
 
 $archive = $ARGV[0];
 @marentries = `"$MAR" -t "$archive"`;
-
 $? && die("Couldn't run \"$MAR\" -t");
 
-shift @marentries;
+system("$MAR -x \"$archive\"") == 0 ||
+  die "Couldn't run $MAR -x";
 
-system("$MAR -x \"$archive\"") == 0 || die "Couldn't run $MAR -x";
+# Try to determine if the mar file contains bzip2 compressed files and if not
+# assume that the mar file contains lzma compressed files. The updatev3.manifest
+# file is checked since a valid mar file must have this file in the root path.
+open(my $testfilename, "updatev3.manifest") or die $!;
+binmode($testfilename);
+read($testfilename, my $bytes, 3);
+if ($bytes eq "BZh") {
+    $MAR_OLD_FORMAT = 1;
+} else {
+    undef $MAR_OLD_FORMAT;
+}
+close $testfilename;
+
+shift @marentries;
 
 foreach (@marentries) {
     tr/\n\r//d;
     my @splits = split(/\t/,$_);
     my $file = $splits[2];
 
-    if ($MAR_OLD_FORMAT == 1) {
+    print "Decompressing: " . $file . "\n";
+    if ($MAR_OLD_FORMAT) {
       system("mv \"$file\" \"$file.bz2\"") == 0 ||
         die "Couldn't mv \"$file\"";
       system("\"$BZIP2\" -d \"$file.bz2\"") == 0 ||
         die "Couldn't decompress \"$file\"";
     }
     else {
       system("mv \"$file\" \"$file.xz\"") == 0 ||
         die "Couldn't mv \"$file\"";
       system("\"$XZ\" -d \"$file.xz\"") == 0 ||
         die "Couldn't decompress \"$file\"";
     }
 }
+
+print "Finished\n";
+