build-support/php: improve PHP builder

This update provide a new feature that allows to build packages without `composer.lock` file (e.g. PHP CodeSniffer).
This commit is contained in:
Pol Dellaiera 2025-01-10 19:10:31 +01:00
parent 0f08212b64
commit 1aeb9801ef
2 changed files with 38 additions and 49 deletions

View File

@ -21,38 +21,17 @@ composerInstallConfigureHook() {
exit 1
fi
install -Dm644 ${composerVendor}/composer.{json,lock} .
install -Dm644 ${composerVendor}/composer.json .
if [[ ! -f "composer.lock" ]]; then
composer \
--no-install \
--no-interaction \
--no-progress \
--optimize-autoloader \
${composerNoDev:+--no-dev} \
${composerNoPlugins:+--no-plugins} \
${composerNoScripts:+--no-scripts} \
update
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
if [[ -f "${composerVendor}/composer.lock" ]]; then
install -Dm644 ${composerVendor}/composer.lock .
fi
chmod +w composer.{json,lock}
if [[ -f "composer.lock" ]]; then
chmod +w composer.lock
fi
chmod +w composer.json
echo "Finished composerInstallConfigureHook"
}

View File

@ -22,8 +22,10 @@ composerVendorConfigureHook() {
install -Dm644 $composerLock ./composer.lock
fi
if [[ ! -f "composer.lock" ]]; then
composer \
--no-cache \
--no-install \
--no-interaction \
--no-progress \
@ -33,25 +35,31 @@ composerVendorConfigureHook() {
${composerNoScripts:+--no-scripts} \
update
install -Dm644 composer.lock -t $out/
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
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
exit 1
fi
fi
chmod +w composer.{json,lock}
if [[ -f "composer.lock" ]]; then
chmod +w composer.lock
fi
chmod +w composer.json
echo "Finished composerVendorConfigureHook"
}
@ -62,10 +70,7 @@ composerVendorBuildHook() {
setComposerEnvVariables
composer \
`# The acpu-autoloader is not reproducible and has to be disabled.` \
`# Upstream PR: https://github.com/composer/composer/pull/12090` \
`# --apcu-autoloader` \
`# --apcu-autoloader-prefix="$(jq -r -c 'try ."content-hash"' < composer.lock)"` \
--no-cache \
--no-interaction \
--no-progress \
--optimize-autoloader \
@ -89,7 +94,12 @@ composerVendorInstallHook() {
echo "Executing composerVendorInstallHook"
mkdir -p $out
cp -ar composer.{json,lock} $(composer config vendor-dir) $out/
cp -ar composer.json $(composer config vendor-dir) $out/
if [[ -f "composer.lock" ]]; then
cp -ar composer.lock $(composer config vendor-dir) $out/
fi
echo "Finished composerVendorInstallHook"
}