1
0
Fork 0

Added phar compiler

pull/9/head
xaav 2011-08-03 23:57:27 +02:00 committed by Jordi Boggiano
parent 256955f0f7
commit 1607ac2404
10 changed files with 247 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/.settings
/.project
/.buildpath
/composer.phar

15
.gitmodules vendored Normal file
View File

@ -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

9
bin/compile Normal file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env php
<?php
require __DIR__.'/../tests/bootstrap.php';
use Composer\Compiler;
$compiler = new Compiler();
$compiler->compile();

107
src/Composer/Compiler.php Normal file
View File

@ -0,0 +1,107 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* 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 <fabien@symfony.com>
*/
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'
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* 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;
}
}

View File

@ -0,0 +1,107 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* 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 <fabien@symfony.com>
*/
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'
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* 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;
}
}

@ -0,0 +1 @@
Subproject commit fd0cb960f526238bad7dc28fee24ba91d6858e06

@ -0,0 +1 @@
Subproject commit c00f87add0823f8f71c4f572595152bf7b2b2daf

@ -0,0 +1 @@
Subproject commit 7e4fecbf8a592268f94704deb6c8ab0f3345af90

@ -0,0 +1 @@
Subproject commit 83d148b10f3acf2a1d1cc427386a1d3d1a125206

@ -0,0 +1 @@
Subproject commit 83186a5f106f33c1c8f8163eef5860ac64ad7679