OSDN Git Service

resurect Phar building code removed in 8483fb709b2285a033515f59b4ad818468a0372a
authorscribu <mail@scribu.net>
Wed, 14 Aug 2013 19:00:34 +0000 (22:00 +0300)
committerscribu <mail@scribu.net>
Wed, 14 Aug 2013 19:00:36 +0000 (22:00 +0300)
changes:

* make WP_CLI_ROOT relative to the root dir, not to php/
* remove man/ and add vendor/rmmcue

php/boot-phar.php [new file with mode: 0644]
utils/make-phar.php [new file with mode: 0644]
utils/test-phar-download [new file with mode: 0755]
utils/update-phar [new file with mode: 0755]

diff --git a/php/boot-phar.php b/php/boot-phar.php
new file mode 100644 (file)
index 0000000..35b82e3
--- /dev/null
@@ -0,0 +1,6 @@
+<?php
+
+define( 'WP_CLI_ROOT', 'phar://wp-cli.phar' );
+
+include WP_CLI_ROOT . '/php/wp-cli.php';
+
diff --git a/utils/make-phar.php b/utils/make-phar.php
new file mode 100644 (file)
index 0000000..df96bab
--- /dev/null
@@ -0,0 +1,88 @@
+<?php
+
+if ( !isset( $argv[1] ) ) {
+       echo "usage: php -dphar.readonly=0 $argv[0] <path> [--quiet]\n";
+       exit(1);
+}
+
+define( 'DEST_PATH', $argv[1] );
+
+define( 'BE_QUIET', in_array( '--quiet', $argv ) );
+
+function get_iterator( $dir ) {
+       return new \RecursiveIteratorIterator(
+               new \RecursiveDirectoryIterator( $dir, FilesystemIterator::SKIP_DOTS )
+       );
+}
+
+function add_file( $phar, $path ) {
+       $key = str_replace( './', '', $path );
+
+       if ( !BE_QUIET )
+               echo "$key - $path\n";
+
+       $phar[ $key ] = file_get_contents( $path );
+}
+
+$phar = new Phar( DEST_PATH, 0, 'wp-cli.phar' );
+
+$phar->startBuffering();
+
+// php files
+foreach ( get_iterator( './php' ) as $path ) {
+       if ( !preg_match( '/\.php$/', $path ) )
+               continue;
+
+       add_file( $phar, $path );
+}
+
+// non-php files
+$additional_dirs = array(
+       './templates',
+);
+
+foreach ( $additional_dirs as $dir ) {
+       foreach ( get_iterator( $dir ) as $path ) {
+               add_file( $phar, $path );
+       }
+}
+
+// dependencies
+$ignored_paths = array(
+       '/.git',
+);
+
+$vendor_dirs = array(
+       './vendor/mustache',
+       './vendor/rmccue',
+       './vendor/wp-cli',
+       './vendor/composer',
+);
+
+foreach ( $vendor_dirs as $vendor_dir ) {
+       foreach ( get_iterator( $vendor_dir ) as $path ) {
+               foreach ( $ignored_paths as $ignore ) {
+                       if ( strpos( $path, $ignore ) )
+                               continue 2;
+               }
+
+               add_file( $phar, $path );
+       }
+}
+
+add_file( $phar, './vendor/autoload.php' );
+
+$phar->setStub( <<<EOB
+#!/usr/bin/env php
+<?php
+Phar::mapPhar();
+include 'phar://wp-cli.phar/php/boot-phar.php';
+__HALT_COMPILER();
+?>
+EOB
+);
+
+$phar->stopBuffering();
+
+echo "Generated " . DEST_PATH . "\n";
+
diff --git a/utils/test-phar-download b/utils/test-phar-download
new file mode 100755 (executable)
index 0000000..f1a47e5
--- /dev/null
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+actual_checksum=$(curl http://wp-cli.org/packages/phar/wp-cli.phar | md5sum | cut -d ' ' -f 1)
+
+echo "expected:" $(curl -s http://wp-cli.org/packages/phar/wp-cli.phar.md5)
+echo "actual:  " $actual_checksum
diff --git a/utils/update-phar b/utils/update-phar
new file mode 100755 (executable)
index 0000000..ea79bf1
--- /dev/null
@@ -0,0 +1,46 @@
+#!/usr/bin/env bash
+
+set -ex
+
+current_rev=$(git rev-parse HEAD)
+current_rev=${current_rev:0:10}
+
+packages_repo=../wp-cli-packages
+
+fname="phar/wp-cli.phar"
+
+# generate archive
+php -dphar.readonly=0 ./utils/make-phar.php $packages_repo/$fname --quiet
+
+cd $packages_repo
+
+# smoke test
+php $fname --version
+
+# check which wp-cli commit the previous Phar archive was based on
+# can't use the md5 hash, since it will be different each time the
+# archive is generated
+new_commit_subj="update wp-cli.phar to wp-cli/wp-cli@$current_rev"
+
+current_commit_subj=$(git show -s --pretty=format:%s HEAD)
+
+if [ "$new_commit_subj" = "$current_commit_subj" ]; then
+       echo "already at latest revision"
+       exit 1
+fi
+
+# generate md5 checksum
+if [ command -v md5sum > /dev/null ]
+then
+       md5hash=$(md5sum $fname)
+else
+       md5hash=$(md5 -r $fname)
+fi
+
+echo $md5hash | cut -d ' ' -f 1 > $fname.md5
+
+git add $fname $fname.md5
+
+git commit -m "$new_commit_subj"
+
+git push