1
0

autoloaderchecker.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. echo
  34. echo "Regenerating composer files for ${app}"
  35. $COMPOSER_COMMAND i --no-dev -d ${app}/composer || exit 1
  36. $COMPOSER_COMMAND dump-autoload -d ${app}/composer || exit 1
  37. fi
  38. done
  39. files=`git diff --name-only`
  40. composerfile=false
  41. for file in $files
  42. do
  43. if [[ $file == *autoload_classmap* ]]
  44. then
  45. composerfile=true
  46. break
  47. fi
  48. done
  49. rm composer.phar
  50. echo
  51. if [ $composerfile = true ]
  52. then
  53. echo "The autoloaders are not up to date"
  54. echo "Please run: bash build/autoloaderchecker.sh"
  55. echo "And commit the result"
  56. exit 1
  57. else
  58. echo "Autoloader up to date. Carry on"
  59. exit 0
  60. fi