autoloaderchecker.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env bash
  2. # SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. COMPOSER_COMMAND="php composer.phar"
  5. if [ -e "composer.phar" ]
  6. then
  7. echo "Composer found: checking for update"
  8. $COMPOSER_COMMAND self-update
  9. else
  10. echo "Composer not found: fetching"
  11. php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
  12. php composer-setup.php --2
  13. php -r "unlink('composer-setup.php');"
  14. fi
  15. COMPOSER_VERSION=$($COMPOSER_COMMAND --version | cut -d" " -f3)
  16. COMPOSER_MAJOR_VERSION=$(echo "$COMPOSER_VERSION" | cut -d"." -f1)
  17. COMPOSER_MINOR_VERSION=$(echo "$COMPOSER_VERSION" | cut -d"." -f2)
  18. COMPOSER_PATCH_VERSION=$(echo "$COMPOSER_VERSION" | cut -d"." -f3)
  19. 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
  20. echo "composer version >= 2.5.5 required. Version found: $COMPOSER_VERSION" >&2
  21. exit 1
  22. fi
  23. REPODIR=`git rev-parse --show-toplevel`
  24. #Redump the main autoloader
  25. echo
  26. echo "Regenerating main autoloader"
  27. $COMPOSER_COMMAND dump-autoload -d $REPODIR
  28. for app in ${REPODIR}/apps/*; do
  29. if git check-ignore ${app} -q ; then
  30. echo
  31. echo "${app} is not shipped. Ignoring autoloader regeneration"
  32. continue
  33. fi
  34. if [[ -d $app ]]; then
  35. echo
  36. echo "Regenerating composer files for ${app}"
  37. $COMPOSER_COMMAND i --no-dev -d ${app}/composer || exit 1
  38. $COMPOSER_COMMAND dump-autoload -d ${app}/composer || exit 1
  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