vendors 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. /*
  27. * Check wether this project is based on the Standard Edition that was
  28. * shipped with vendors or not.
  29. */
  30. if (is_dir($vendorDir.'/symfony') && !is_dir($vendorDir.'/symfony/.git') && !in_array('--reinstall', $argv)) {
  31. exit(<<<EOF
  32. Your project seems to be based on a Standard Edition that includes vendors.
  33. Try to run ./bin/vendors install --reinstall
  34. EOF
  35. );
  36. }
  37. if (!is_dir($vendorDir)) {
  38. mkdir($vendorDir, 0777, true);
  39. }
  40. // versions
  41. $versions = array();
  42. if ('install' === $command && file_exists($rootDir.'/deps.lock')) {
  43. foreach (file($rootDir.'/deps.lock', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
  44. $parts = array_values(array_filter(explode(' ', $line)));
  45. if (2 !== count($parts)) {
  46. exit(sprintf('The deps version file is not valid (near "%s")', $line));
  47. }
  48. $versions[$parts[0]] = $parts[1];
  49. }
  50. }
  51. $newversions = array();
  52. $deps = parse_ini_file($rootDir.'/deps', true, INI_SCANNER_RAW);
  53. if (false === $deps) {
  54. exit("The deps file is not valid ini syntax. Perhaps missing a trailing newline?\n");
  55. }
  56. foreach ($deps as $name => $dep) {
  57. $dep = array_map('trim', $dep);
  58. // revision
  59. if (isset($versions[$name])) {
  60. $rev = $versions[$name];
  61. } else {
  62. $rev = isset($dep['version']) ? $dep['version'] : 'origin/HEAD';
  63. }
  64. // install dir
  65. $installDir = isset($dep['target']) ? $vendorDir.'/'.$dep['target'] : $vendorDir.'/'.$name;
  66. if (in_array('--reinstall', $argv)) {
  67. if (PHP_OS == 'WINNT') {
  68. system(sprintf('rmdir /S /Q %s', escapeshellarg(realpath($installDir))));
  69. } else {
  70. system(sprintf('rm -rf %s', escapeshellarg($installDir)));
  71. }
  72. }
  73. echo "> Installing/Updating $name\n";
  74. // url
  75. if (!isset($dep['git'])) {
  76. exit(sprintf('The "git" value for the "%s" dependency must be set.', $name));
  77. }
  78. $url = $dep['git'];
  79. if (!is_dir($installDir)) {
  80. system(sprintf('git clone %s %s', escapeshellarg($url), escapeshellarg($installDir)));
  81. }
  82. system(sprintf('cd %s && git fetch origin && git reset --hard %s', escapeshellarg($installDir), escapeshellarg($rev)));
  83. if ('update' === $command) {
  84. ob_start();
  85. system(sprintf('cd %s && git log -n 1 --format=%%H', escapeshellarg($installDir)));
  86. $newversions[] = trim($name.' '.ob_get_clean());
  87. }
  88. }
  89. // update?
  90. if ('update' === $command) {
  91. file_put_contents($rootDir.'/deps.lock', implode("\n", $newversions));
  92. }
  93. // php on windows can't use the shebang line from system()
  94. $interpreter = PHP_OS == 'WINNT' ? 'php.exe' : '';
  95. // Update the bootstrap files
  96. system(sprintf('%s %s', $interpreter, escapeshellarg($rootDir.'/vendor/bundles/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php')));
  97. // Update assets
  98. system(sprintf('%s %s assets:install %s', $interpreter, escapeshellarg($rootDir.'/app/console'), escapeshellarg($rootDir.'/web/')));
  99. // Remove the cache
  100. system(sprintf('%s %s cache:clear --no-warmup', $interpreter, escapeshellarg($rootDir.'/app/console')));