vendors 3.8 KB

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