123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- #!/usr/bin/env php
- <?php
- /*
- * This file is part of the Symfony Standard Edition.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- $rootDir = dirname(__DIR__);
- $vendorDir = $rootDir.'/vendor';
- array_shift($argv);
- if (!isset($argv[0])) {
- die(<<<EOF
- Symfony2 vendors script management.
- Specify a command to run:
- install: install vendors as specified in deps or deps.lock (recommended)
- update: update vendors to their latest versions (as specified in deps)
- EOF
- );
- }
- if (!in_array($command = array_shift($argv), array('install', 'update'))) {
- die(sprintf("Command \"%s\" does not exist.\n", $command));
- }
- if (!is_dir($vendorDir)) {
- mkdir($vendorDir, 0777, true);
- }
- // versions
- $versions = array();
- if ('install' === $command && file_exists($rootDir.'/deps.lock')) {
- foreach (file($rootDir.'/deps.lock') as $line) {
- if (!trim($line)) {
- continue;
- }
- $parts = array_values(array_filter(explode(' ', trim($line))));
- if (2 !== count($parts)) {
- die(sprintf('The deps version file is not valid (near "%s")', $line));
- }
- $versions[$parts[0]] = $parts[1];
- }
- }
- foreach (file($rootDir.'/deps') as $line) {
- if (!trim($line)) {
- continue;
- }
- $parts = array_values(array_filter(explode(' ', trim($line))));
- if (3 !== count($parts)) {
- die(sprintf('The deps file is not valid (near "%s")', $line));
- }
- list($name, $path, $url) = $parts;
- $rev = 'origin/HEAD';
- if (false !== strpos($url, '@')) {
- list($url, $rev) = explode('@', $url);
- }
- if (isset($versions[$name])) {
- $rev = $versions[$name];
- }
- $installDir = $vendorDir.'/'.$path.'/'.$name;
- if (in_array('--reinstall', $argv)) {
- if (PHP_OS == 'WINNT') {
- system('rmdir /S /Q "'.realpath($installDir)).'"';
- } else {
- system('rm -rf "'.$installDir.'"');
- }
- }
- echo "> Installing/Updating $name\n";
- if (!is_dir($installDir)) {
- system(sprintf('git clone %s "%s"', $url, $installDir));
- }
- system(sprintf('cd "%s" && git fetch origin && git reset --hard %s', $installDir, $rev));
- }
- // update?
- if ('update' === $command) {
- $deps = array();
- foreach (file($rootDir.'/deps') as $line) {
- if (!trim($line)) {
- continue;
- }
- $parts = array_values(array_filter(explode(' ', trim($line))));
- if (3 !== count($parts)) {
- die(sprintf('The deps file is not valid (near "%s")', $line));
- }
- list($name, $path, $url) = $parts;
- ob_start();
- system('cd "'.$vendorDir.'/'.$path.'/'.$name.'"; git log -n 1 --format=%H');
- $deps[] = trim($name.' '.ob_get_clean());
- }
- file_put_contents($rootDir.'/deps.lock', implode("\n", $deps));
- }
- // php on windows can't use the shebang line from system()
- $interpreter = PHP_OS == 'WINNT' ? 'php.exe' : '';
- // Update the bootstrap files
- system(sprintf('%s "%s/bin/build_bootstrap"', $interpreter, $rootDir));
- // Update assets
- system(sprintf('%s "%s/app/console" assets:install "%s/web/"', $interpreter, $rootDir, $rootDir));
- // Remove the cache
- system(sprintf('%s "%s/app/console" cache:clear --no-warmup', $interpreter, $rootDir));
|