#!/usr/bin/env php * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ set_time_limit(0); $rootDir = dirname(__DIR__); $vendorDir = $rootDir.'/vendor'; array_shift($argv); if (!isset($argv[0])) { echo(<< $dep) { $dep = array_map('trim', $dep); // install dir $installDir = isset($dep['target']) ? $vendorDir.'/'.$dep['target'] : $vendorDir.'/'.$name; if (in_array('--reinstall', $argv) && realpath($installDir)) { if (defined('PHP_WINDOWS_VERSION_BUILD')) { system(sprintf('rmdir /S /Q %s', escapeshellarg(realpath($installDir)))); } else { system(sprintf('rm -rf %s', escapeshellarg($installDir))); } clearstatcache(); } if ('install' === $command || 'update' === $command) { echo PHP_EOL.'> Installing/Updating '.$name.PHP_EOL; // url if (!isset($dep['git'])) { echo(sprintf('The "git" value for the "%s" dependency must be set.', $name).PHP_EOL); exit(1); } $url = $dep['git']; if ('update' === $command && is_dir($installDir)) { ob_start(); system(sprintf('cd %s && git config --get remote.origin.url', escapeshellarg($installDir))); $current_url = trim(ob_get_clean()); if ($current_url !== $url) { if (PHP_OS == 'WINNT') { system(sprintf('rmdir /S /Q %s', escapeshellarg(realpath($installDir)))); } else { system(sprintf('rm -rf %s', escapeshellarg($installDir))); } clearstatcache(); } } if (!is_dir($installDir)) { system(sprintf('git clone %s %s', escapeshellarg($url), escapeshellarg($installDir))); } // revision if (isset($versions[$name])) { $rev = $versions[$name]; } else { $rev = isset($dep['version']) ? $dep['version'] : 'origin/HEAD'; } $status = system(sprintf('cd %s && git status --porcelain', escapeshellarg($installDir))); if (!empty($status)) { echo(sprintf('"%s" has local modifications. Please revert or commit/push them before running this command again.', $name).PHP_EOL); exit(1); } $current_rev = system(sprintf('cd %s && git rev-list --max-count=1 HEAD', escapeshellarg($installDir))); if ($current_rev === $rev) { continue; } system(sprintf('cd %s && git fetch origin && git reset --hard %s', escapeshellarg($installDir), escapeshellarg($rev))); } if ('update' === $command || 'lock' === $command) { ob_start(); system(sprintf('cd %s && git log -n 1 --format=%%H', escapeshellarg($installDir))); $newversion = trim(ob_get_clean()); ob_start(); system(sprintf('cd %s && git name-rev --tags --name-only %s', escapeshellarg($installDir), $newversion)); // remove trailing ^0 from tags, those are the tags themselves $niceversion = preg_replace('/\^0$/', '', trim(ob_get_clean())); // undefined is returned in case no name-rev could be found if ('undefined' !== $niceversion) { $newversions[] = $name.' '.$niceversion; } else { $newversions[] = $name.' '.$newversion; } } } // update? if ('update' === $command || 'lock' === $command) { echo PHP_EOL.'> Updating deps.lock'.PHP_EOL; file_put_contents($rootDir.'/deps.lock', implode("\n", $newversions)."\n"); } // php on windows can't use the shebang line from system() $interpreter = defined('PHP_WINDOWS_VERSION_BUILD') ? 'php.exe' : 'php'; // Update the bootstrap files if (!@system(sprintf('%s %s %s', $interpreter, escapeshellarg($rootDir.'/vendor/bundles/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php'), escapeshellarg($rootDir)))){ echo PHP_EOL.">Updating the bootstrap files failed.\nPlease run command \"php vendor/bundles/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php /\" manually".PHP_EOL; } // Update assets if (!@system(sprintf('%s %s assets:install %s', $interpreter, escapeshellarg($rootDir.'/app/console'), escapeshellarg($rootDir.'/web/')))){ echo PHP_EOL.">Updating assets failed.\nPlease run command \"php app/console assets:install web\" manually".PHP_EOL; } // Remove the cache if (!@system(sprintf('%s %s cache:clear --no-warmup', $interpreter, escapeshellarg($rootDir.'/app/console')))){ echo PHP_EOL.">Updating assets failed.\nPlease run command \"php app/console cache:clear --no-warmup\" manually".PHP_EOL; }