From: Marcus Boerger Date: Fri, 23 Nov 2007 16:44:04 +0000 (+0000) Subject: - Improve make pharcmd X-Git-Tag: RELEASE_2_0_0a1~1294 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4b18c23fd1d0184c75df64181a4cbbadcf63d05e;p=php - Improve make pharcmd - Add -b to pack and stub-set commands of phar.phar --- diff --git a/ext/phar/Makefile.frag b/ext/phar/Makefile.frag index abe8e184ee..3e79356fa1 100755 --- a/ext/phar/Makefile.frag +++ b/ext/phar/Makefile.frag @@ -4,10 +4,22 @@ $(srcdir)/phar_path_check.c: $(srcdir)/phar_path_check.re pharcmd: $(builddir)/phar.php $(builddir)/phar.phar -$(builddir)/phar.php: $(srcdir)/build_precommand.php $(srcdir)/phar/*.inc $(srcdir)/phar/*.php - $(PHP_EXECUTABLE) $(srcdir)/build_precommand.php > $(builddir)/phar.php +$(builddir)/phar.php: $(srcdir)/build_precommand.php $(srcdir)/phar/*.inc $(srcdir)/phar/*.php $(SAPI_CLI_PATH) + if test -x "$(PHP_EXECUTABLE)"; then \ + export PHP="$(PHP_EXECUTABLE)"; \ + else \ + export PHP="$(top_builddir)/$(SAPI_CLI_PATH)"; \ + fi; \ + $$PHP $(srcdir)/build_precommand.php > $(builddir)/phar.php -$(builddir)/phar.phar: $(builddir)/phar.php $(srcdir)/phar/*.inc $(srcdir)/phar/*.php - $(PHP_EXECUTABLE) -d phar.readonly=0 $(srcdir)/phar.php pack -f $(builddir)/phar.phar -a pharcommand -c auto -x CVS -p 0 -s $(srcdir)/phar/phar.php -h sha1 $(srcdir)/phar/ +$(builddir)/phar.phar: $(builddir)/phar.php $(srcdir)/phar/*.inc $(srcdir)/phar/*.php $(SAPI_CLI_PATH) + if test -x "$(PHP_EXECUTABLE)"; then \ + export PHP="$(PHP_EXECUTABLE)"; \ + export BANG="$(PHP_EXECUTABLE)"; \ + else \ + export PHP="$(top_builddir)/$(SAPI_CLI_PATH)"; \ + export BANG="$(INSTALL_ROOT)$(bindir)/$(program_prefix)php$(program_suffix)$(EXEEXT)"; \ + fi; \ + $$PHP -d phar.readonly=0 $(srcdir)/phar.php pack -f $(builddir)/phar.phar -a pharcommand -c auto -x CVS -p 0 -s $(srcdir)/phar/phar.php -h sha1 -b "$$BANG" $(srcdir)/phar/ @chmod +x $(builddir)/phar.phar diff --git a/ext/phar/phar.phar b/ext/phar/phar.phar index 9686edc739..b69bce64d3 100755 Binary files a/ext/phar/phar.phar and b/ext/phar/phar.phar differ diff --git a/ext/phar/phar/pharcommand.inc b/ext/phar/phar/pharcommand.inc index 8f2cf106f1..cd4120e224 100755 --- a/ext/phar/phar/pharcommand.inc +++ b/ext/phar/phar/pharcommand.inc @@ -62,6 +62,12 @@ class PharCommand extends CLICommand 'val' => NULL, 'inf' => ' Provide an alias name for the phar file.' ), + 'b' => array( + 'typ' => 'any', + 'val' => NULL, + 'inf' => ' Hash-bang line to start the archieve (e.g. #!/usr/bin/php). The hash ' + .' mark itself \'#!\' and the newline character are optional.' + ), 'c' => array( 'typ' => 'compalg', 'val' => NULL, @@ -362,7 +368,7 @@ class PharCommand extends CLICommand */ static function cli_cmd_arg_pack() { - $args = self::phar_args('acFhilpsx', 'pharnew'); + $args = self::phar_args('abcFhilpsx', 'pharnew'); $args[''] = array( 'typ' => 'any', @@ -379,34 +385,51 @@ class PharCommand extends CLICommand /** * Set the stub */ - public function phar_set_stub_begin(Phar $phar, $stub, $loader = NULL) + public function phar_set_stub_begin(Phar $phar, $stub, $loader = NULL, $hashbang = NULL) { if (isset($stub)) { - if (isset($loader)) { - $c = file_get_contents($stub); - $s = ''; + $c = file_get_contents($stub); + + if (substr($c, 0, 2) == '#!') { + if (strpos($c, "\n") !== false) { + if (!isset($hashbang)) { + $hashbang = substr($c, 0, strpos($c, "\n") + 1); + } + $c = substr($c, strpos($c, "\n") + 1); + } else { + if (!isset($hashbang)) { + $hashbang = $c; + } + $c = NULL; + } + } - if (substr($c, 0, 2) == '#!') { - $s .= substr($c, 0, strpos($c, "\n") + 1); + if (isset($hashbang)) { + if (substr($hashbang, 0, 2) != '#!') { + $hashbang = '#!' . $hashbang; } + if (substr($hashbang, -1) != "\n") { + $hashbang .= "\n"; + } + } - $s .= ""; + if (isset($loader)) { + $s = ""; $s .= file_get_contents($loader); $s .= "'; + $s .= $c; - if (substr($c,0,1) == '#') { - $s.= substr($c,strpos($c, "\n")+1); - } - - $phar->setStub($s); + $phar->setStub($hasbang . $s); } else { - $phar->setStub(file_get_contents($stub)); + $phar->setStub($hasbang . $c); } return new SplFileInfo($stub); } @@ -447,6 +470,7 @@ class PharCommand extends CLICommand } $alias = $this->args['a']['val']; + $hashbang = $this->args['b']['val']; $archive = $this->args['f']['val']; $hash = $this->args['h']['val']; $regex = $this->args['i']['val']; @@ -460,7 +484,7 @@ class PharCommand extends CLICommand $phar->startBuffering(); - $stub = $this->phar_set_stub_begin($phar, $stub, $loader); + $stub = $this->phar_set_stub_begin($phar, $stub, $loader, $hashbang); if (!is_array($input)) { $this->phar_add($phar, $level, $input, $regex, $invregex, $stub, NULL, isset($loader)); @@ -916,7 +940,7 @@ class PharCommand extends CLICommand */ public function cli_cmd_arg_stub_set() { - $args = self::phar_args('Fps', 'phar'); + $args = self::phar_args('bFps', 'phar'); $args['s']['val'] = 'php://stdin'; return $args; } @@ -929,11 +953,12 @@ class PharCommand extends CLICommand */ public function cli_cmd_run_stub_set() { - $phar = $this->args['f']['val']; - $stub = $this->args['s']['val']; - $loader = $this->args['p']['val']; + $hashbang = $this->args['b']['val']; + $phar = $this->args['f']['val']; + $stub = $this->args['s']['val']; + $loader = $this->args['p']['val']; - $this->phar_set_stub_begin($phar, $stub, $loader); + $this->phar_set_stub_begin($phar, $stub, $loader, $hashbang); $this->phar_set_stub_end($phar, $stub, $loader); } // }}}