1
0

autoloaderchecker.sh 2.0 KB

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