vendors 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. * This file is part of the Symfony Standard Edition.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. $rootDir = dirname(__DIR__);
  12. $vendorDir = $rootDir.'/vendor';
  13. array_shift($argv);
  14. if (!isset($argv[0])) {
  15. exit(<<<EOF
  16. Symfony2 vendors script management.
  17. Specify a command to run:
  18. install: install vendors as specified in deps or deps.lock (recommended)
  19. update: update vendors to their latest versions (as specified in deps)
  20. EOF
  21. );
  22. }
  23. if (!in_array($command = array_shift($argv), array('install', 'update'))) {
  24. exit(sprintf("Command \"%s\" does not exist.\n", $command));
  25. }
  26. if (!is_dir($vendorDir)) {
  27. mkdir($vendorDir, 0777, true);
  28. }
  29. if (!file_exists($rootDir.'/app/config/parameters.ini')) {
  30. copy($rootDir.'/app/config/parameters.ini.dist', $rootDir.'/app/config/parameters.ini');
  31. }
  32. // versions
  33. $versions = array();
  34. if ('install' === $command && file_exists($rootDir.'/deps.lock')) {
  35. foreach (file($rootDir.'/deps.lock', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
  36. $parts = array_values(array_filter(explode(' ', $line)));
  37. if (2 !== count($parts)) {
  38. exit(sprintf('The deps version file is not valid (near "%s")', $line));
  39. }
  40. $versions[$parts[0]] = $parts[1];
  41. }
  42. }
  43. $newversions = array();
  44. $deps = parse_ini_file($rootDir.'/deps', true, INI_SCANNER_RAW);
  45. foreach ($deps as $name => $dep) {
  46. // revision
  47. if (isset($versions[$name])) {
  48. $rev = $versions[$name];
  49. } else {
  50. $rev = isset($dep['version']) ? $dep['version'] : 'origin/HEAD';
  51. }
  52. // install dir
  53. $installDir = isset($dep['target']) ? $vendorDir.'/'.$dep['target'] : $vendorDir.'/'.$name;
  54. if (in_array('--reinstall', $argv)) {
  55. if (PHP_OS == 'WINNT') {
  56. system(sprintf('rmdir /S /Q %s', escapeshellarg(realpath($installDir))));
  57. } else {
  58. system(sprintf('rm -rf %s', escapeshellarg($installDir)));
  59. }
  60. }
  61. echo "> Installing/Updating $name\n";
  62. // url
  63. if (!isset($dep['git'])) {
  64. exit(sprintf('The "git" value for the "%s" dependency must be set.', $name));
  65. }
  66. $url = $dep['git'];
  67. if (!is_dir($installDir)) {
  68. system(sprintf('git clone %s %s', escapeshellarg($url), escapeshellarg($installDir)));
  69. }
  70. system(sprintf('cd %s && git fetch origin && git reset --hard %s', escapeshellarg($installDir), escapeshellarg($rev)));
  71. if ('update' === $command) {
  72. ob_start();
  73. system(sprintf('cd %s && git log -n 1 --format=%%H', escapeshellarg($installDir)));
  74. $newversions[] = trim($name.' '.ob_get_clean());
  75. }
  76. }
  77. // update?
  78. if ('update' === $command) {
  79. file_put_contents($rootDir.'/deps.lock', implode("\n", $newversions));
  80. }
  81. // php on windows can't use the shebang line from system()
  82. $interpreter = PHP_OS == 'WINNT' ? 'php.exe' : '';
  83. // Update the bootstrap files
  84. system(sprintf('%s %s', $interpreter, escapeshellarg($rootDir.'/vendor/bundles/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php')));
  85. // Update assets
  86. system(sprintf('%s %s assets:install %s', $interpreter, escapeshellarg($rootDir.'/app/console'), escapeshellarg($rootDir.'/web/')));
  87. // Remove the cache
  88. system(sprintf('%s %s cache:clear --no-warmup', $interpreter, escapeshellarg($rootDir.'/app/console')));