Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Replaced vendors.sh by bin/vendors php script to install vendors to r…
…un unit tests
  • Loading branch information
francisbesset committed Jun 30, 2011
1 parent 2d9047f commit 55ee41c
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 38 deletions.
102 changes: 102 additions & 0 deletions bin/vendors
@@ -0,0 +1,102 @@
#!/usr/bin/env php
<?php

/*
* (c) Fabien Potencier <fabien@symfony.com>
*/

$rootDir = dirname(__DIR__);
$vendorDir = $rootDir.'/vendor';

array_shift($argv);
if (!isset($argv[0])) {
exit(<<<EOF
I18nRoutingBundle vendors script management.
Specify a command to run:
install: install vendors
update [--reinstall]: update vendors
EOF
);
}

if (!in_array($command = array_shift($argv), array('install', 'update'))) {
exit(sprintf("Command \"%s\" does not exist.\n", $command));
}

if ('install' === $command && is_dir($vendorDir.'/symfony/.git')) {
exit(<<<EOF
Vendors already installed
Try to run ./bin/vendors update or ./bin/vendors update --reinstall
EOF
);
} elseif ('update' === $command && !is_dir($vendorDir.'/symfony/.git') && !in_array('--reinstall', $argv)) {
exit(<<<EOF
Vendors are not installed
Try to run ./bin/vendors update --reinstall or ./bin/vendors install
EOF
);
}

if (!is_file($rootDir.'/deps')) {
exit(<<<EOF
The $rootDir files does not exists
EOF
);
}

if (!is_dir($vendorDir)) {
mkdir($vendorDir, 0777, true);
}

$newversions = array();
$deps = parse_ini_file($rootDir.'/deps', true, INI_SCANNER_RAW);
foreach ($deps as $name => $dep) {
// revision
if (isset($versions[$name])) {
$rev = $versions[$name];
} else {
$rev = isset($dep['version']) ? $dep['version'] : 'origin/HEAD';
}

// install dir
$installDir = isset($dep['target']) ? $vendorDir.'/'.$dep['target'] : $vendorDir.'/'.$name;
if (in_array('--reinstall', $argv)) {
if (PHP_OS == 'WINNT') {
system(sprintf('rmdir /S /Q %s', escapeshellarg(realpath($installDir))));
} else {
system(sprintf('rm -rf %s', escapeshellarg($installDir)));
}
}

echo "> Installing/Updating $name\n";

// url
if (!isset($dep['git'])) {
exit(sprintf('The "git" value for the "%s" dependency must be set.', $name));
}
$url = $dep['git'];

if (!is_dir($installDir)) {
system(sprintf('git clone %s %s', escapeshellarg($url), escapeshellarg($installDir)));
}

system(sprintf('cd %s && git fetch origin && git reset --hard %s', escapeshellarg($installDir), escapeshellarg($rev)));

if ('update' === $command) {
ob_start();
system(sprintf('cd %s && git log -n 1 --format=%%H', escapeshellarg($installDir)));
$newversions[] = trim($name.' '.ob_get_clean());
}
}
8 changes: 8 additions & 0 deletions deps
@@ -0,0 +1,8 @@
[symfony]
git=http://github.com/symfony/symfony.git

[doctrine-common]
git=http://github.com/doctrine/common.git

[doctrine-dbal]
git=http://github.com/doctrine/dbal.git
38 changes: 0 additions & 38 deletions vendors.sh

This file was deleted.

0 comments on commit 55ee41c

Please sign in to comment.