You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.3 KiB

  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. FOUND_COMPOSER_BIN=$(grep --recursive --fixed-strings 'Bamarni\\Composer\\Bin' $REPODIR/lib/composer/composer/)
  29. if [ -n "$FOUND_COMPOSER_BIN" ]; then
  30. echo "The main autoloader contains the composer bin plugin"
  31. echo "Run composer again with --no-dev and commit the result"
  32. exit 1
  33. fi
  34. for app in ${REPODIR}/apps/*; do
  35. if git check-ignore ${app} -q ; then
  36. echo
  37. echo "${app} is not shipped. Ignoring autoloader regeneration"
  38. continue
  39. fi
  40. if [[ -d $app ]]; then
  41. echo
  42. echo "Regenerating composer files for ${app}"
  43. $COMPOSER_COMMAND i --no-dev -d ${app}/composer || exit 1
  44. $COMPOSER_COMMAND dump-autoload -d ${app}/composer || exit 1
  45. git checkout ${app}/composer/composer/installed.php
  46. fi
  47. done
  48. files=`git diff --name-only`
  49. composerfile=false
  50. for file in $files
  51. do
  52. if [[ $file == *autoload_classmap* ]]
  53. then
  54. composerfile=true
  55. break
  56. fi
  57. done
  58. rm composer.phar
  59. echo
  60. if [ $composerfile = true ]
  61. then
  62. echo "The autoloaders are not up to date"
  63. echo "Please run: bash build/autoloaderchecker.sh"
  64. echo "And commit the result"
  65. exit 1
  66. else
  67. echo "Autoloader up to date. Carry on"
  68. exit 0
  69. fi