wez             Thu Apr  8 09:36:11 2004 EDT

  Modified files:              
    /php-src/win32/build        mkdist.php 
  Log:
  Add code to fetch the pear bundle based on pear/go-pear-list.php
  For the moment, this is turned off, but it should be turned on ready for
  the next RC.
  (waiting for feedback from Edin and the PEAR guys)
  
  
http://cvs.php.net/diff.php/php-src/win32/build/mkdist.php?r1=1.9&r2=1.10&ty=u
Index: php-src/win32/build/mkdist.php
diff -u php-src/win32/build/mkdist.php:1.9 php-src/win32/build/mkdist.php:1.10
--- php-src/win32/build/mkdist.php:1.9  Wed Feb 25 18:38:03 2004
+++ php-src/win32/build/mkdist.php      Thu Apr  8 09:36:11 2004
@@ -1,4 +1,4 @@
-<?php # $Id: mkdist.php,v 1.9 2004/02/25 23:38:03 sniper Exp $
+<?php # $Id: mkdist.php,v 1.10 2004/04/08 13:36:11 wez Exp $
 /* piece together a windows binary distro */
 
 $build_dir = $argv[1];
@@ -134,6 +134,66 @@
        fclose($fp);
 }
 
+/* very light-weight function to extract a single named file from
+ * a gzipped tarball.  This makes assumptions about the files
+ * based on the PEAR info set in $packages. */
+function extract_file_from_tarball($pkg, $filename, $dest_dir) /* {{{ */
+{
+       global $packages;
+
+       $name = $pkg . '-' . $packages[$pkg];
+       $tarball = $dest_dir . "/" . $name . '.tgz';
+       $filename = $name . '/' . $filename;
+       $destfilename = $dest_dir . "/" . basename($filename);
+
+       $fp = gzopen($tarball, 'rb');
+
+       $done = false;
+       do {
+               /* read the header */
+               $hdr_data = gzread($fp, 512);
+               if (strlen($hdr_data) == 0)
+                       break;
+               $checksum = 0;
+               for ($i = 0; $i < 148; $i++)
+                       $checksum += ord($hdr_data{$i});
+               for ($i = 148; $i < 156; $i++)
+                       $checksum += 32;
+               for ($i = 156; $i < 512; $i++)
+                       $checksum += ord($hdr_data{$i});
+
+               $hdr = 
unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor",
 $hdr_data);
+
+               $hdr['checksum'] = octdec(trim($hdr['checksum']));
+
+               if ($hdr['checksum'] != $checksum) {
+                       echo "Checksum for $tarball $hdr[filename] is invalid\n";
+                       print_r($hdr);
+                       return;
+               }
+
+               $hdr['size'] = octdec(trim($hdr['size']));
+               echo "File: $hdr[filename] $hdr[size]\n";
+               
+               if ($filename == $hdr['filename']) {
+                       echo "Found the file we want\n";
+                       $dest = fopen($destfilename, 'wb');
+                       $x = stream_copy_to_stream($fp, $dest, $hdr['size']);
+                       fclose($dest);
+                       echo "Wrote $x bytes into $destfilename\n";
+                       break;
+               }
+               
+               /* skip body of the file */
+               $size = 512 * ceil((int)$hdr['size'] / 512);
+               echo "Skipping $size bytes\n";
+               gzseek($fp, gztell($fp) + $size);
+               
+       } while (!$done);
+       
+} /* }}} */
+
+
 /* the core dll */
 copy("$build_dir/php.exe", "$dist_dir/php.exe");
 copy("$build_dir/$phpdll", "$dist_dir/$phpdll");
@@ -271,6 +331,45 @@
        closedir($d);
 }
 
+/* change this next line to true to use good-old
+ * hand-assembled go-pear-bundle from the snapshot template */
+$use_pear_template = true;
+
+if (!$use_pear_template) {
+       /* Let's do a PEAR-less pear setup */
+       mkdir("$dist_dir/PEAR");
+       mkdir("$dist_dir/PEAR/go-pear-bundle");
+
+       /* grab the bootstrap script */
+       echo "Downloading go-pear\n";
+       copy("http://go-pear.org/";, "$dist_dir/PEAR/go-pear.php");
+
+       /* import the package list -- sets $packages variable */
+       include "pear/go-pear-list.php";
+
+       /* download the packages into the destination */
+       echo "Fetching packages\n";
+
+       foreach ($packages as $name => $version) {
+               $filename = "$name-$version.tgz";
+               $destfilename = "$dist_dir/PEAR/go-pear-bundle/$filename";
+               if (file_exists($destfilename))
+                       continue;
+               $url = "http://pear.php.net/get/$filename";;
+               echo "Downloading $name from $url\n";
+               flush();
+               copy($url, $destfilename);
+       }
+
+       echo "Download complete.  Extracting bootstrap files\n";
+
+       /* Now, we want PEAR.php, Getopt.php (Console_Getopt) and Tar.php (Archive_Tar)
+        * broken out of the tarballs */
+       extract_file_from_tarball('PEAR', 'PEAR.php', "$dist_dir/PEAR/go-pear-bundle");
+       extract_file_from_tarball('Archive_Tar', 'Archive/Tar.php', 
"$dist_dir/PEAR/go-pear-bundle");
+       extract_file_from_tarball('Console_Getopt', 'Console/Getopt.php', 
"$dist_dir/PEAR/go-pear-bundle");
+}
+       
 /* add extras from the template dir */
 if (file_exists($snapshot_template)) {
        $items = glob("$snapshot_template/*");
@@ -282,8 +381,10 @@
                        if ($bi == 'dlls' || $bi == 'symbols') {
                                continue;
                        } else if ($bi == 'PEAR') {
-                               /* copy to top level */
-                               copy_dir($item, "$dist_dir/$bi");
+                               if ($use_pear_template) {
+                                       /* copy to top level */
+                                       copy_dir($item, "$dist_dir/$bi");
+                               }
                        } else {
                                /* copy that dir into extras */
                                copy_dir($item, "$dist_dir/extras/$bi");

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to