autoloaderchecker.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env bash
  2. COMPOSER_COMMAND="php composer.phar"
  3. if [ -e "composer.phar" ]
  4. then
  5. echo "Composer found: checking for update"
  6. $COMPOSER_COMMAND self-update
  7. else
  8. echo "Composer not found: fetching"
  9. php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
  10. php composer-setup.php --2
  11. php -r "unlink('composer-setup.php');"
  12. fi
  13. COMPOSER_VERSION=$($COMPOSER_COMMAND --version | cut -d" " -f3)
  14. COMPOSER_MAJOR_VERSION=$(echo "$COMPOSER_VERSION" | cut -d"." -f1)
  15. COMPOSER_MINOR_VERSION=$(echo "$COMPOSER_VERSION" | cut -d"." -f2)
  16. COMPOSER_PATCH_VERSION=$(echo "$COMPOSER_VERSION" | cut -d"." -f3)
  17. if ! [ "$COMPOSER_MAJOR_VERSION" -gt 2 -o \( "$COMPOSER_MAJOR_VERSION" -eq 2 -a "$COMPOSER_MINOR_VERSION" -ge 6 \) -o \( "$COMPOSER_MAJOR_VERSION" -eq 2 -a "$COMPOSER_MINOR_VERSION" -eq 5 -a "$COMPOSER_PATCH_VERSION" -ge 5 \) ]; then
  18. echo "composer version >= 2.5.5 required. Version found: $COMPOSER_VERSION" >&2
  19. exit 1
  20. fi
  21. REPODIR=`git rev-parse --show-toplevel`
  22. #Redump the main autoloader
  23. echo
  24. echo "Regenerating main autoloader"
  25. $COMPOSER_COMMAND dump-autoload -d $REPODIR
  26. for app in ${REPODIR}/apps/*; do
  27. if git check-ignore ${app} -q ; then
  28. echo
  29. echo "${app} is not shipped. Ignoring autoloader regeneration"
  30. continue
  31. fi
  32. if [[ -d $app ]]; then
  33. if [[ -e ${app}/composer/composer.json ]]; then
  34. echo
  35. echo "Regenerating composer files for ${app}"
  36. $COMPOSER_COMMAND i --no-dev -d ${app}/composer
  37. $COMPOSER_COMMAND dump-autoload -d ${app}/composer
  38. fi
  39. fi
  40. done
  41. files=`git diff --name-only`
  42. composerfile=false
  43. for file in $files
  44. do
  45. if [[ $file == *autoload_classmap* ]]
  46. then
  47. composerfile=true
  48. break
  49. fi
  50. done
  51. rm composer.phar
  52. echo
  53. if [ $composerfile = true ]
  54. then
  55. echo "The autoloaders are not up to date"
  56. echo "Please run: bash build/autoloaderchecker.sh"
  57. echo "And commit the result"
  58. exit 1
  59. else
  60. echo "Autoloader up to date. Carry on"
  61. exit 0
  62. fi