vendors 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. die(<<<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. die(sprintf("Command \"%s\" does not exist.\n", $command));
  25. }
  26. if (!is_dir($vendorDir)) {
  27. mkdir($vendorDir, 0777, true);
  28. }
  29. // versions
  30. $versions = array();
  31. if ('install' === $command && file_exists($rootDir.'/deps.lock')) {
  32. foreach (file($rootDir.'/deps.lock') as $line) {
  33. if (!trim($line)) {
  34. continue;
  35. }
  36. $parts = array_values(array_filter(explode(' ', trim($line))));
  37. if (2 !== count($parts)) {
  38. die(sprintf('The deps version file is not valid (near "%s")', $line));
  39. }
  40. $versions[$parts[0]] = $parts[1];
  41. }
  42. }
  43. foreach (file($rootDir.'/deps') as $line) {
  44. if (!trim($line)) {
  45. continue;
  46. }
  47. $parts = array_values(array_filter(explode(' ', trim($line))));
  48. if (3 !== count($parts)) {
  49. die(sprintf('The deps file is not valid (near "%s")', $line));
  50. }
  51. list($name, $path, $url) = $parts;
  52. $rev = 'origin/HEAD';
  53. if (false !== strpos($url, '@')) {
  54. list($url, $rev) = explode('@', $url);
  55. }
  56. if (isset($versions[$name])) {
  57. $rev = $versions[$name];
  58. }
  59. $installDir = $vendorDir.'/'.$path.'/'.$name;
  60. if (in_array('--reinstall', $argv)) {
  61. if (PHP_OS == 'WINNT') {
  62. system('rmdir /S /Q "'.realpath($installDir)).'"';
  63. } else {
  64. system('rm -rf "'.$installDir.'"');
  65. }
  66. }
  67. echo "> Installing/Updating $name\n";
  68. if (!is_dir($installDir)) {
  69. system(sprintf('git clone %s "%s"', $url, $installDir));
  70. }
  71. system(sprintf('cd "%s" && git fetch origin && git reset --hard %s', $installDir, $rev));
  72. }
  73. // update?
  74. if ('update' === $command) {
  75. $deps = array();
  76. foreach (file($rootDir.'/deps') as $line) {
  77. if (!trim($line)) {
  78. continue;
  79. }
  80. $parts = array_values(array_filter(explode(' ', trim($line))));
  81. if (3 !== count($parts)) {
  82. die(sprintf('The deps file is not valid (near "%s")', $line));
  83. }
  84. list($name, $path, $url) = $parts;
  85. ob_start();
  86. system('cd "'.$vendorDir.'/'.$path.'/'.$name.'"; git log -n 1 --format=%H');
  87. $deps[] = trim($name.' '.ob_get_clean());
  88. }
  89. file_put_contents($rootDir.'/deps.lock', implode("\n", $deps));
  90. }
  91. // php on windows can't use the shebang line from system()
  92. $interpreter = PHP_OS == 'WINNT' ? 'php.exe' : '';
  93. // Update the bootstrap files
  94. system(sprintf('%s "%s/bin/build_bootstrap"', $interpreter, $rootDir));
  95. // Update assets
  96. system(sprintf('%s "%s/app/console" assets:install "%s/web/"', $interpreter, $rootDir, $rootDir));
  97. // Remove the cache
  98. system(sprintf('%s "%s/app/console" cache:clear --no-warmup', $interpreter, $rootDir));