From 1607ac2404b0b279d7af623f6a3534342cd534d0 Mon Sep 17 00:00:00 2001 From: xaav Date: Wed, 3 Aug 2011 23:57:27 +0200 Subject: [PATCH] Added phar compiler --- .gitignore | 4 ++ .gitmodules | 15 +++++ bin/compile | 9 +++ src/Composer/Compiler.php | 107 ++++++++++++++++++++++++++++++ src/Composer/Compiler.php~HEAD | 107 ++++++++++++++++++++++++++++++ src/Symfony/Component/BrowserKit | 1 + src/Symfony/Component/ClassLoader | 1 + src/Symfony/Component/Config | 1 + src/Symfony/Component/Finder | 1 + src/Symfony/Component/Process | 1 + 10 files changed, 247 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 bin/compile create mode 100644 src/Composer/Compiler.php create mode 100644 src/Composer/Compiler.php~HEAD create mode 160000 src/Symfony/Component/BrowserKit create mode 160000 src/Symfony/Component/ClassLoader create mode 160000 src/Symfony/Component/Config create mode 160000 src/Symfony/Component/Finder create mode 160000 src/Symfony/Component/Process diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..f66dc16eb --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/.settings +/.project +/.buildpath +/composer.phar \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..5dbd59568 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,15 @@ +[submodule "src/Symfony/Component/Process"] + path = src/Symfony/Component/Process + url = https://github.com/symfony/Process.git +[submodule "src/Symfony/Component/Finder"] + path = src/Symfony/Component/Finder + url = https://github.com/symfony/Finder.git +[submodule "src/Symfony/Component/Config"] + path = src/Symfony/Component/Config + url = https://github.com/symfony/Config.git +[submodule "src/Symfony/Component/ClassLoader"] + path = src/Symfony/Component/ClassLoader + url = https://github.com/symfony/ClassLoader.git +[submodule "src/Symfony/Component/BrowserKit"] + path = src/Symfony/Component/BrowserKit + url = https://github.com/symfony/BrowserKit.git diff --git a/bin/compile b/bin/compile new file mode 100644 index 000000000..9d966fcb2 --- /dev/null +++ b/bin/compile @@ -0,0 +1,9 @@ +#!/usr/bin/env php +compile(); diff --git a/src/Composer/Compiler.php b/src/Composer/Compiler.php new file mode 100644 index 000000000..3e533bf98 --- /dev/null +++ b/src/Composer/Compiler.php @@ -0,0 +1,107 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer; + +use Symfony\Component\Finder\Finder; +use Symfony\Component\Process\Process; + +/** + * The Compiler class compiles the Silex framework. + * + * @author Fabien Potencier + */ +class Compiler +{ + protected $version; + + public function compile($pharFile = 'composer.phar') + { + if (file_exists($pharFile)) { + unlink($pharFile); + } + + $process = new Process('git log --pretty="%h %ci" -n1 HEAD'); + if ($process->run() > 0) { + throw new \RuntimeException('The git binary cannot be found.'); + } + $this->version = trim($process->getOutput()); + + $phar = new \Phar($pharFile, 0, 'composer.phar'); + $phar->setSignatureAlgorithm(\Phar::SHA1); + + $phar->startBuffering(); + + $finder = new Finder(); + $finder->files() + ->ignoreVCS(true) + ->name('*.php') + ->notName('Compiler.php') + ->in(__DIR__.'/../Composer') + ; + + foreach ($finder as $file) { + $this->addFile($phar, $file); + } + + $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../tests/bootstrap.php')); + $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../bin/composer')); + + // Stubs + $phar->setStub($this->getStub()); + + $phar->stopBuffering(); + + $phar->compressFiles(\Phar::GZ); + + $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../LICENSE'), false); + + unset($phar); + } + + protected function addFile($phar, $file, $strip = true) + { + $path = str_replace(dirname(dirname(__DIR__)).DIRECTORY_SEPARATOR, '', $file->getRealPath()); + + if ($strip) { + $content = php_strip_whitespace($file); + } else { + $content = "\n".file_get_contents($file)."\n"; + } + + $content = str_replace('@package_version@', $this->version, $content); + + $phar->addFromString($path, $content); + } + + protected function getStub() + { + return <<<'EOF' + + * Jordi Boggiano + * + * For the full copyright and license information, please view + * the license that is located at the bottom of this file. + */ + +Phar::mapPhar('composer.phar'); + +require 'phar://composer.phar/bin/composer'; + +__HALT_COMPILER(); +EOF; + } +} diff --git a/src/Composer/Compiler.php~HEAD b/src/Composer/Compiler.php~HEAD new file mode 100644 index 000000000..3e533bf98 --- /dev/null +++ b/src/Composer/Compiler.php~HEAD @@ -0,0 +1,107 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer; + +use Symfony\Component\Finder\Finder; +use Symfony\Component\Process\Process; + +/** + * The Compiler class compiles the Silex framework. + * + * @author Fabien Potencier + */ +class Compiler +{ + protected $version; + + public function compile($pharFile = 'composer.phar') + { + if (file_exists($pharFile)) { + unlink($pharFile); + } + + $process = new Process('git log --pretty="%h %ci" -n1 HEAD'); + if ($process->run() > 0) { + throw new \RuntimeException('The git binary cannot be found.'); + } + $this->version = trim($process->getOutput()); + + $phar = new \Phar($pharFile, 0, 'composer.phar'); + $phar->setSignatureAlgorithm(\Phar::SHA1); + + $phar->startBuffering(); + + $finder = new Finder(); + $finder->files() + ->ignoreVCS(true) + ->name('*.php') + ->notName('Compiler.php') + ->in(__DIR__.'/../Composer') + ; + + foreach ($finder as $file) { + $this->addFile($phar, $file); + } + + $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../tests/bootstrap.php')); + $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../bin/composer')); + + // Stubs + $phar->setStub($this->getStub()); + + $phar->stopBuffering(); + + $phar->compressFiles(\Phar::GZ); + + $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../LICENSE'), false); + + unset($phar); + } + + protected function addFile($phar, $file, $strip = true) + { + $path = str_replace(dirname(dirname(__DIR__)).DIRECTORY_SEPARATOR, '', $file->getRealPath()); + + if ($strip) { + $content = php_strip_whitespace($file); + } else { + $content = "\n".file_get_contents($file)."\n"; + } + + $content = str_replace('@package_version@', $this->version, $content); + + $phar->addFromString($path, $content); + } + + protected function getStub() + { + return <<<'EOF' + + * Jordi Boggiano + * + * For the full copyright and license information, please view + * the license that is located at the bottom of this file. + */ + +Phar::mapPhar('composer.phar'); + +require 'phar://composer.phar/bin/composer'; + +__HALT_COMPILER(); +EOF; + } +} diff --git a/src/Symfony/Component/BrowserKit b/src/Symfony/Component/BrowserKit new file mode 160000 index 000000000..fd0cb960f --- /dev/null +++ b/src/Symfony/Component/BrowserKit @@ -0,0 +1 @@ +Subproject commit fd0cb960f526238bad7dc28fee24ba91d6858e06 diff --git a/src/Symfony/Component/ClassLoader b/src/Symfony/Component/ClassLoader new file mode 160000 index 000000000..c00f87add --- /dev/null +++ b/src/Symfony/Component/ClassLoader @@ -0,0 +1 @@ +Subproject commit c00f87add0823f8f71c4f572595152bf7b2b2daf diff --git a/src/Symfony/Component/Config b/src/Symfony/Component/Config new file mode 160000 index 000000000..7e4fecbf8 --- /dev/null +++ b/src/Symfony/Component/Config @@ -0,0 +1 @@ +Subproject commit 7e4fecbf8a592268f94704deb6c8ab0f3345af90 diff --git a/src/Symfony/Component/Finder b/src/Symfony/Component/Finder new file mode 160000 index 000000000..83d148b10 --- /dev/null +++ b/src/Symfony/Component/Finder @@ -0,0 +1 @@ +Subproject commit 83d148b10f3acf2a1d1cc427386a1d3d1a125206 diff --git a/src/Symfony/Component/Process b/src/Symfony/Component/Process new file mode 160000 index 000000000..83186a5f1 --- /dev/null +++ b/src/Symfony/Component/Process @@ -0,0 +1 @@ +Subproject commit 83186a5f106f33c1c8f8163eef5860ac64ad7679