Skip to content

Commit

Permalink
Updating to use Burgomaster
Browse files Browse the repository at this point in the history
  • Loading branch information
mtdowling committed Aug 18, 2014
1 parent 0a7c9e3 commit 39e2b9a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 160 deletions.
32 changes: 32 additions & 0 deletions Makefile
@@ -0,0 +1,32 @@
all: clean coverage docs

test:
vendor/bin/phpunit

coverage:
vendor/bin/phpunit --coverage-html=build/artifacts/coverage

integration:
vendor/bin/phpunit -c phpunit.functional.xml

view-coverage:
open build/artifacts/coverage/index.html

clean:
rm -rf build/artifacts
cd docs && make clean

docs:
cd docs && make html

view-docs:
open docs/_build/html/index.html

package: burgomaster
time php build/packager.php

burgomaster:
mkdir -p build/artifacts
curl -s https://raw.githubusercontent.com/mtdowling/Burgomaster/0.0.1/src/Burgomaster.php > build/artifacts/Burgomaster.php

.PHONY: docs burgomaster
35 changes: 0 additions & 35 deletions build/aws-autoloader.php

This file was deleted.

140 changes: 21 additions & 119 deletions build/packager.php
@@ -1,124 +1,26 @@
<?php
/**
* Packages the zip and phar file using a staging directory.
*/

function debug_log($message)
{
echo $message . "\n";
}

function deep_copy($from, $to)
{
$dir = dirname($to);
if (!is_dir($dir)) {
mkdir($dir, 0777, true);
}
copy($from, $to);
}

// Files to be added to the package
function create_staging_dir($baseDir)
{
debug_log("Creating staging directory at: $baseDir");
debug_log(" Cleaning $baseDir");
exec("rm -rf $baseDir");
mkdir($baseDir);
chdir(__DIR__ . '/..');

debug_log(" Copying meta-files to $baseDir");
foreach (['README.md', 'LICENSE.md', 'NOTICE.md'] as $file) {
deep_copy($file, $baseDir . '/Aws/' . $file);
}

// Copy the autoloader
debug_log(' Copying aws-autoloader');
copy(__DIR__ . '/aws-autoloader.php', $baseDir . '/aws-autoloader.php');

$directories = [
'src',
'vendor/guzzle/guzzle/src',
'vendor/symfony/event-dispatcher',
'vendor/symfony/class-loader',
'vendor/doctrine/cache/lib',
'vendor/psr/log',
'vendor/monolog/monolog/src'
];

debug_log(' Copying files');
foreach ($directories as $dir) {
recursive_copy($dir, $baseDir);
}

// Delete the duplicate LICENSE
unlink($baseDir . '/LICENSE');

debug_log(" Created staging directory at: $baseDir");
}
require __DIR__ . '/artifacts/Burgomaster.php';

$stageDirectory = __DIR__ . '/artifacts/staging';
$projectRoot = __DIR__ . '/../';
$burgomaster = new \Burgomaster($stageDirectory, $projectRoot);

/**
* Recursively copy a dependency
*/
function recursive_copy($fromDir, $baseDir)
{
// File extensions added to the output
$exts = array_fill_keys(['php', 'pem'], true);

$fromDir = realpath($fromDir);
$iter = new RecursiveDirectoryIterator($fromDir);
$iter = new RecursiveIteratorIterator($iter);

debug_log(" > From $fromDir");

$total = 0;
foreach ($iter as $file) {
if (isset($exts[$file->getExtension()])
|| $file->getBaseName() == 'LICENSE'
) {
$toPath = str_replace($fromDir, '', (string) $file);
$toPath = $baseDir . '/' . $toPath;
deep_copy((string) $file, $toPath);
$total++;
}
}

debug_log(" Copied $total files");
}

function create_phar($baseDir, $dest)
{
debug_log('Creating full phar file');
$phar = new Phar($dest, 0, 'aws.phar');
$phar->buildFromDirectory($baseDir);
$phar->setStub(file_get_contents(__DIR__ . '/phar-stub.php'));

debug_log(" > Created at $dest");
}

function test_phar($baseDir, $phar)
{
debug_log('Testing the phar');
exec('php ' . __DIR__ . '/test_phar.php', $output, $ret);
if ($ret !== 0) {
die("Testing the phar failed with exit code {$ret}\n"
. implode("\n", $output));
}
debug_log(' > Phar is OK: ' . implode("\n", $output));
foreach (['README.md', 'LICENSE.md', 'NOTICE.md'] as $file) {
$burgomaster->deepCopy($file, $file);
}

function create_zip($baseDir, $dest)
{
debug_log('Creating zip file');
chdir($baseDir);
exec("zip -r $dest ./");
debug_log(" > Created at $dest");
chdir(__DIR__);
}

$baseDir = realpath(__DIR__ . '/..') . '/build/artifacts/staging';

create_staging_dir($baseDir);
create_phar($baseDir, __DIR__ . '/artifacts/aws.phar');
test_phar($baseDir, __DIR__ . '/artifacts/aws.phar');
create_zip($baseDir, __DIR__ . '/artifacts/aws.zip');
// Copy each dependency to the staging directory. Copy *.php and *.pem files.
$burgomaster->recursiveCopy('src/Aws', 'Aws', ['php', 'json']);
$burgomaster->recursiveCopy('vendor/guzzle/guzzle/src/Guzzle', 'Guzzle', ['php', 'pem']);
$burgomaster->recursiveCopy('vendor/doctrine/cache/lib/Doctrine', 'Doctrine');
$burgomaster->recursiveCopy('vendor/psr/log/Psr', 'Psr');
$burgomaster->recursiveCopy('vendor/monolog/monolog/src/Monolog', 'Monlog');
$burgomaster->recursiveCopy('vendor/symfony/event-dispatcher/Symfony', 'Symfony');

$burgomaster->createAutoloader();
$burgomaster->createZip(__DIR__ . '/artifacts/aws.zip');
$burgomaster->createPhar(__DIR__ . '/artifacts/aws.phar');
$burgomaster->startSection('test_phar');
$burgomaster->debug('Phar output: '
. $burgomaster->exec('php ' . __DIR__ . '/test_phar.php'));
$burgomaster->endSection();
5 changes: 0 additions & 5 deletions build/phar-stub.php

This file was deleted.

1 change: 0 additions & 1 deletion composer.json
Expand Up @@ -31,7 +31,6 @@
"ext-openssl": "*",
"monolog/monolog": "1.4.*",
"phpunit/phpunit": "4.*",
"symfony/class-loader": "2.*",
"symfony/yaml": "2.*"
},
"autoload": {
Expand Down

0 comments on commit 39e2b9a

Please sign in to comment.