build-support/php: run shfmt on hooks

This commit is contained in:
Pol Dellaiera
2025-06-22 22:45:31 +02:00
parent 7628af124b
commit bb0c422eb6
3 changed files with 168 additions and 168 deletions
@@ -11,60 +11,60 @@ preInstallHooks+=(composerInstallInstallHook)
source @phpScriptUtils@
composerInstallConfigureHook() {
echo "Executing composerInstallConfigureHook"
echo "Executing composerInstallConfigureHook"
setComposerRootVersion
setComposerRootVersion
if [[ ! -e "${composerVendor}" ]]; then
echo "No local composer vendor found." >&2
exit 1
fi
if [[ ! -e "${composerVendor}" ]]; then
echo "No local composer vendor found." >&2
exit 1
fi
install -Dm644 ${composerVendor}/composer.json .
install -Dm644 ${composerVendor}/composer.json .
if [[ -f "${composerVendor}/composer.lock" ]]; then
install -Dm644 ${composerVendor}/composer.lock .
fi
if [[ -f "${composerVendor}/composer.lock" ]]; then
install -Dm644 ${composerVendor}/composer.lock .
fi
if [[ -f "composer.lock" ]]; then
chmod +w composer.lock
fi
if [[ -f "composer.lock" ]]; then
chmod +w composer.lock
fi
chmod +w composer.json
chmod +w composer.json
echo "Finished composerInstallConfigureHook"
echo "Finished composerInstallConfigureHook"
}
composerInstallBuildHook() {
echo "Executing composerInstallBuildHook"
echo "Executing composerInstallBuildHook"
echo "Finished composerInstallBuildHook"
echo "Finished composerInstallBuildHook"
}
composerInstallCheckHook() {
echo "Executing composerInstallCheckHook"
echo "Executing composerInstallCheckHook"
checkComposerValidate
checkComposerValidate
echo "Finished composerInstallCheckHook"
echo "Finished composerInstallCheckHook"
}
composerInstallInstallHook() {
echo "Executing composerInstallInstallHook"
echo "Executing composerInstallInstallHook"
cp -ar ${composerVendor}/* .
cp -ar ${composerVendor}/* .
# Copy the relevant files only in the store.
mkdir -p "$out"/share/php/"${pname}"
cp -r . "$out"/share/php/"${pname}"/
# Copy the relevant files only in the store.
mkdir -p "$out"/share/php/"${pname}"
cp -r . "$out"/share/php/"${pname}"/
# Create symlinks for the binaries.
mapfile -t BINS < <(jq -r -c 'try (.bin[] | select(test(".bat$")? | not) )' composer.json)
for bin in "${BINS[@]}"; do
echo -e "\e[32mCreating symlink ${bin}...\e[0m"
mkdir -p "$out/bin"
ln -s "$out/share/php/${pname}/${bin}" "$out/bin/$(basename "$bin")"
done
# Create symlinks for the binaries.
mapfile -t BINS < <(jq -r -c 'try (.bin[] | select(test(".bat$")? | not) )' composer.json)
for bin in "${BINS[@]}"; do
echo -e "\e[32mCreating symlink ${bin}...\e[0m"
mkdir -p "$out/bin"
ln -s "$out/share/php/${pname}/${bin}" "$out/bin/$(basename "$bin")"
done
echo "Finished composerInstallInstallHook"
echo "Finished composerInstallInstallHook"
}
@@ -10,111 +10,111 @@ preCheckHooks+=(composerVendorCheckHook)
preInstallHooks+=(composerVendorInstallHook)
composerVendorConfigureHook() {
echo "Executing composerVendorConfigureHook"
echo "Executing composerVendorConfigureHook"
setComposerRootVersion
setComposerRootVersion
if [[ -f "composer.lock" ]]; then
echo -e "\e[32mUsing \`composer.lock\` file from the source package\e[0m"
fi
if [[ -e "$composerLock" ]]; then
echo -e "\e[32mUsing user provided \`composer.lock\` file from \`$composerLock\`\e[0m"
install -Dm644 $composerLock ./composer.lock
fi
if [[ ! -f "composer.lock" ]]; then
composer \
--no-cache \
--no-install \
--no-interaction \
--no-progress \
--optimize-autoloader \
${composerNoDev} \
${composerNoPlugins} \
${composerNoScripts} \
update
if [[ -f "composer.lock" ]]; then
echo -e "\e[32mUsing \`composer.lock\` file from the source package\e[0m"
install -Dm644 composer.lock -t $out/
echo
echo -e "\e[31mERROR: No composer.lock found\e[0m"
echo
echo -e '\e[31mNo composer.lock file found, consider adding one to your repository to ensure reproducible builds.\e[0m'
echo -e "\e[31mIn the meantime, a composer.lock file has been generated for you in $out/composer.lock\e[0m"
echo
echo -e '\e[31mTo fix the issue:\e[0m'
echo -e "\e[31m1. Copy the composer.lock file from $out/composer.lock to the project's source:\e[0m"
echo -e "\e[31m cp $out/composer.lock <path>\e[0m"
echo -e '\e[31m2. Add the composerLock attribute, pointing to the copied composer.lock file:\e[0m'
echo -e '\e[31m composerLock = ./composer.lock;\e[0m'
echo
exit 1
fi
fi
if [[ -e "$composerLock" ]]; then
echo -e "\e[32mUsing user provided \`composer.lock\` file from \`$composerLock\`\e[0m"
install -Dm644 $composerLock ./composer.lock
fi
if [[ -f "composer.lock" ]]; then
chmod +w composer.lock
fi
if [[ ! -f "composer.lock" ]]; then
composer \
--no-cache \
--no-install \
--no-interaction \
--no-progress \
--optimize-autoloader \
${composerNoDev} \
${composerNoPlugins} \
${composerNoScripts} \
update
chmod +w composer.json
if [[ -f "composer.lock" ]]; then
install -Dm644 composer.lock -t $out/
echo
echo -e "\e[31mERROR: No composer.lock found\e[0m"
echo
echo -e '\e[31mNo composer.lock file found, consider adding one to your repository to ensure reproducible builds.\e[0m'
echo -e "\e[31mIn the meantime, a composer.lock file has been generated for you in $out/composer.lock\e[0m"
echo
echo -e '\e[31mTo fix the issue:\e[0m'
echo -e "\e[31m1. Copy the composer.lock file from $out/composer.lock to the project's source:\e[0m"
echo -e "\e[31m cp $out/composer.lock <path>\e[0m"
echo -e '\e[31m2. Add the composerLock attribute, pointing to the copied composer.lock file:\e[0m'
echo -e '\e[31m composerLock = ./composer.lock;\e[0m'
echo
exit 1
fi
fi
if [[ -f "composer.lock" ]]; then
chmod +w composer.lock
fi
chmod +w composer.json
echo "Finished composerVendorConfigureHook"
echo "Finished composerVendorConfigureHook"
}
composerVendorBuildHook() {
echo "Executing composerVendorBuildHook"
echo "Executing composerVendorBuildHook"
setComposerEnvVariables
setComposerEnvVariables
composer \
--no-cache \
--no-interaction \
--no-progress \
--optimize-autoloader \
${composerNoDev} \
${composerNoPlugins} \
${composerNoScripts} \
install
composer \
--no-cache \
--no-interaction \
--no-progress \
--optimize-autoloader \
${composerNoDev} \
${composerNoPlugins} \
${composerNoScripts} \
install
echo "Finished composerVendorBuildHook"
echo "Finished composerVendorBuildHook"
}
composerVendorCheckHook() {
echo "Executing composerVendorCheckHook"
echo "Executing composerVendorCheckHook"
checkComposerValidate
checkComposerValidate
echo "Finished composerVendorCheckHook"
echo "Finished composerVendorCheckHook"
}
composerVendorInstallHook() {
echo "Executing composerVendorInstallHook"
echo "Executing composerVendorInstallHook"
mkdir -p $out
mkdir -p $out
cp -ar composer.json $(composer config vendor-dir) $out/
mapfile -t installer_paths < <(jq -r -c 'try((.extra."installer-paths") | keys[])' composer.json)
cp -ar composer.json $(composer config vendor-dir) $out/
mapfile -t installer_paths < <(jq -r -c 'try((.extra."installer-paths") | keys[])' composer.json)
for installer_path in "${installer_paths[@]}"; do
# Remove everything after {$name} placeholder
installer_path="${installer_path/\{\$name\}*/}";
out_installer_path="$out/${installer_path/\{\$name\}*/}";
# Copy the installer path if it exists
if [[ -d "$installer_path" ]]; then
mkdir -p $(dirname "$out_installer_path")
echo -e "\e[32mCopying installer path $installer_path to $out_installer_path\e[0m"
cp -ar "$installer_path" "$out_installer_path"
# Strip out the git repositories
find $out_installer_path -name .git -type d -prune -print -exec rm -rf {} ";"
fi
done
if [[ -f "composer.lock" ]]; then
cp -ar composer.lock $out/
for installer_path in "${installer_paths[@]}"; do
# Remove everything after {$name} placeholder
installer_path="${installer_path/\{\$name\}*/}"
out_installer_path="$out/${installer_path/\{\$name\}*/}"
# Copy the installer path if it exists
if [[ -d "$installer_path" ]]; then
mkdir -p $(dirname "$out_installer_path")
echo -e "\e[32mCopying installer path $installer_path to $out_installer_path\e[0m"
cp -ar "$installer_path" "$out_installer_path"
# Strip out the git repositories
find $out_installer_path -name .git -type d -prune -print -exec rm -rf {} ";"
fi
done
echo "Finished composerVendorInstallHook"
if [[ -f "composer.lock" ]]; then
cp -ar composer.lock $out/
fi
echo "Finished composerVendorInstallHook"
}
@@ -2,69 +2,69 @@ declare -g version
declare -g -i composerStrictValidation="${composerStrictValidation:-0}"
setComposerRootVersion() {
if [[ -n $version ]]; then
echo -e "\e[32mSetting COMPOSER_ROOT_VERSION to $version\e[0m"
export COMPOSER_ROOT_VERSION="$version"
fi
if [[ -n $version ]]; then
echo -e "\e[32mSetting COMPOSER_ROOT_VERSION to $version\e[0m"
export COMPOSER_ROOT_VERSION="$version"
fi
}
setComposerEnvVariables() {
echo -e "\e[32mSetting some required environment variables for Composer...\e[0m"
export COMPOSER_MIRROR_PATH_REPOS=1
export COMPOSER_HTACCESS_PROTECT=0
export COMPOSER_FUND=0
echo -e "\e[32mSetting some required environment variables for Composer...\e[0m"
export COMPOSER_MIRROR_PATH_REPOS=1
export COMPOSER_HTACCESS_PROTECT=0
export COMPOSER_FUND=0
}
checkComposerValidate() {
command="composer validate --strict --quiet --no-interaction --no-check-all --no-check-lock"
if ! $command; then
echo
echo -e "\e[31mERROR: composer files validation failed\e[0m"
echo
echo -e '\e[31mThe validation of the composer.json failed.\e[0m'
echo -e '\e[31mMake sure that the file composer.json is valid.\e[0m'
echo
echo -e '\e[31mTo address the issue efficiently, follow one of these steps:\e[0m'
echo -e '\e[31m 1. File an issue in the project'\''s issue tracker with detailed information, and apply any available remote patches as a temporary solution '\('with fetchpatch'\)'.\e[0m'
echo -e '\e[31m 2. If an immediate fix is needed or if reporting upstream isn'\''t suitable, develop a temporary local patch.\e[0m'
echo
command="composer validate --strict --quiet --no-interaction --no-check-all --no-check-lock"
if ! $command; then
echo
echo -e "\e[31mERROR: composer files validation failed\e[0m"
echo
echo -e '\e[31mThe validation of the composer.json failed.\e[0m'
echo -e '\e[31mMake sure that the file composer.json is valid.\e[0m'
echo
echo -e '\e[31mTo address the issue efficiently, follow one of these steps:\e[0m'
echo -e '\e[31m 1. File an issue in the project'\''s issue tracker with detailed information, and apply any available remote patches as a temporary solution '\('with fetchpatch'\)'.\e[0m'
echo -e '\e[31m 2. If an immediate fix is needed or if reporting upstream isn'\''t suitable, develop a temporary local patch.\e[0m'
echo
if [[ "${composerStrictValidation}" == "1" ]]; then
echo
echo -e '\e[33mThis check is blocking, set the attribute composerStrictValidation to false to make it not blocking.\e[0m'
echo
exit 1
else
echo
echo -e '\e[33mThis check is not blocking, but it is recommended to fix the issue.\e[0m'
echo
fi
if [[ "${composerStrictValidation}" == "1" ]]; then
echo
echo -e '\e[33mThis check is blocking, set the attribute composerStrictValidation to false to make it not blocking.\e[0m'
echo
exit 1
else
echo
echo -e '\e[33mThis check is not blocking, but it is recommended to fix the issue.\e[0m'
echo
fi
fi
command="composer validate --strict --no-ansi --no-interaction --quiet --no-check-all --check-lock"
if ! $command; then
echo
echo -e "\e[31mERROR: composer files validation failed\e[0m"
echo
echo -e '\e[31mThe validation of the composer.json and composer.lock failed.\e[0m'
echo -e '\e[31mMake sure that the file composer.lock is consistent with composer.json.\e[0m'
echo
echo -e '\e[31mThis often indicates an issue with the upstream project, which can typically be resolved by reporting the issue to the relevant project maintainers.\e[0m'
echo
echo -e '\e[31mTo address the issue efficiently, follow one of these steps:\e[0m'
echo -e '\e[31m 1. File an issue in the project'\''s issue tracker with detailed information '\('run '\''composer update --lock --no-install'\'' to fix the issue'\)', and apply any available remote patches as a temporary solution with '\('with fetchpatch'\)'.\e[0m'
echo -e '\e[31m 2. If an immediate fix is needed or if reporting upstream isn'\''t suitable, develop a temporary local patch.\e[0m'
echo
command="composer validate --strict --no-ansi --no-interaction --quiet --no-check-all --check-lock"
if ! $command; then
echo
echo -e "\e[31mERROR: composer files validation failed\e[0m"
echo
echo -e '\e[31mThe validation of the composer.json and composer.lock failed.\e[0m'
echo -e '\e[31mMake sure that the file composer.lock is consistent with composer.json.\e[0m'
echo
echo -e '\e[31mThis often indicates an issue with the upstream project, which can typically be resolved by reporting the issue to the relevant project maintainers.\e[0m'
echo
echo -e '\e[31mTo address the issue efficiently, follow one of these steps:\e[0m'
echo -e '\e[31m 1. File an issue in the project'\''s issue tracker with detailed information '\('run '\''composer update --lock --no-install'\'' to fix the issue'\)', and apply any available remote patches as a temporary solution with '\('with fetchpatch'\)'.\e[0m'
echo -e '\e[31m 2. If an immediate fix is needed or if reporting upstream isn'\''t suitable, develop a temporary local patch.\e[0m'
echo
if [[ "${composerStrictValidation}" == "1" ]]; then
echo
echo -e '\e[33mThis check is blocking, set the attribute composerStrictValidation to false to make it not blocking.\e[0m'
echo
exit 1
else
echo
echo -e '\e[33mThis check is not blocking, but it is recommended to fix the issue.\e[0m'
echo
fi
if [[ "${composerStrictValidation}" == "1" ]]; then
echo
echo -e '\e[33mThis check is blocking, set the attribute composerStrictValidation to false to make it not blocking.\e[0m'
echo
exit 1
else
echo
echo -e '\e[33mThis check is not blocking, but it is recommended to fix the issue.\e[0m'
echo
fi
fi
}