nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 113 lines 3.4 kB view raw
1# shellcheck shell=bash 2 3declare -g out 4declare -g pname 5declare -g composerVendor 6declare -g -i composerStrictValidation="${composerStrictValidation:-0}" 7 8declare -g composerNoDev 9declare -g composerNoPlugins 10declare -g composerNoScripts 11 12declare -ga composerFlags=() 13 14[[ -n "${composerNoDev-1}" ]] && composerFlags+=(--no-dev) 15[[ -n "${composerNoPlugins-1}" ]] && composerFlags+=(--no-plugins) 16[[ -n "${composerNoScripts-1}" ]] && composerFlags+=(--no-scripts) 17 18preConfigureHooks+=(composerInstallConfigureHook) 19preBuildHooks+=(composerInstallBuildHook) 20preCheckHooks+=(composerInstallCheckHook) 21preInstallHooks+=(composerInstallInstallHook) 22 23# shellcheck source=/dev/null 24source @phpScriptUtils@ 25 26composerInstallConfigureHook() { 27 echo "Running phase: composerInstallConfigureHook" 28 29 setComposerRootVersion 30 31 if [[ ! -e "${composerVendor}" ]]; then 32 echo -e "\e[31mERROR: The 'composerVendor' attribute is missing or invalid.\e[0m" >&2 33 exit 1 34 fi 35 36 install -Dm644 "${composerVendor}"/composer.json . 37 38 if [[ -f "${composerVendor}/composer.lock" ]]; then 39 install -Dm644 "${composerVendor}"/composer.lock . 40 fi 41 42 if [[ -f "composer.lock" ]]; then 43 chmod +w composer.lock 44 fi 45 46 chmod +w composer.json 47 48 echo "Finished phase: composerInstallConfigureHook" 49} 50 51composerInstallBuildHook() { 52 echo "Running phase: composerInstallBuildHook" 53 54 setComposerEnvVariables 55 56 echo -e "\e[32mRestoring Composer vendor directory to '${COMPOSER_VENDOR_DIR}'...\e[0m" 57 cp -r "${composerVendor}/${COMPOSER_VENDOR_DIR}" . 58 chmod -R +w "${COMPOSER_VENDOR_DIR}" 59 60 mapfile -t installer_paths < <(jq -r -c 'try((.extra."installer-paths") | keys[])' composer.json) 61 for installer_path in "${installer_paths[@]}"; do 62 # Remove everything after {$name} placeholder 63 installer_path="${installer_path/\{\$name\}*/}" 64 if [[ -e "${composerVendor}/${installer_path}" ]]; then 65 echo -e "\e[32mRestoring custom installer path: ${installer_path}\e[0m" 66 mkdir -p "$(dirname "${installer_path}")" 67 cp -ar "${composerVendor}/${installer_path}" "${installer_path}" 68 # Strip out the git repositories 69 find "${installer_path}" -name .git -type d -prune -print -exec rm -rf {} ";" || true 70 chmod -R +w "${installer_path}" 71 fi 72 done 73 74 # Run this only if composer.lock is available. 75 # e.g., php-codesniffer doesn't need a composer.lock file. 76 if [[ -f "composer.lock" ]]; then 77 echo -e "\e[32mEnsuring Composer dependencies are locked to 'composer.lock'...\e[0m" 78 composer \ 79 --no-cache \ 80 --no-interaction \ 81 --no-progress \ 82 "${composerFlags[@]}" \ 83 install 84 fi 85 86 echo "Finished phase: composerInstallBuildHook" 87} 88 89composerInstallCheckHook() { 90 echo "Running phase: composerInstallCheckHook" 91 92 checkComposerValidate 93 94 echo "Finished phase: composerInstallCheckHook" 95} 96 97composerInstallInstallHook() { 98 echo "Running phase: composerInstallInstallHook" 99 100 # Copy the relevant files only in the store. 101 mkdir -p "$out"/share/php/"${pname}" 102 cp -r . "$out"/share/php/"${pname}"/ 103 104 # Create symlinks for the binaries. 105 mapfile -t BINS < <(jq -r -c 'try (.bin[] | select(test(".bat$")? | not) )' composer.json) 106 for bin in "${BINS[@]}"; do 107 echo -e "\e[32mInstalling binary: ${bin}\e[0m" 108 mkdir -p "$out/bin" 109 ln -s "$out/share/php/${pname}/${bin}" "$out/bin/$(basename "$bin")" 110 done 111 112 echo "Finished phase: composerInstallInstallHook" 113}