From 2b12e3efe343646af31ef26b9c8f31d876fadc8e Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Wed, 4 Oct 2023 14:58:40 +0200 Subject: [PATCH] php.buildComposerProject: improve workflow in case of missing `composer.lock` file --- .../php/hooks/composer-install-hook.sh | 26 +++++++++++++++++-- .../php/hooks/composer-repository-hook.sh | 24 ++++++++++++++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/php/hooks/composer-install-hook.sh b/pkgs/build-support/php/hooks/composer-install-hook.sh index 4aa9e631c14c..b1b5e2ac553d 100644 --- a/pkgs/build-support/php/hooks/composer-install-hook.sh +++ b/pkgs/build-support/php/hooks/composer-install-hook.sh @@ -22,12 +22,34 @@ composerInstallConfigureHook() { fi if [[ ! -f "composer.lock" ]]; then - echo "No composer.lock file found, consider adding one to your repository to ensure reproducible builds." + composer \ + --no-ansi \ + --no-install \ + --no-interaction \ + ${composerNoDev:+--no-dev} \ + ${composerNoPlugins:+--no-plugins} \ + ${composerNoScripts:+--no-scripts} \ + update + + mkdir -p $out + cp composer.lock $out/ + + echo + echo 'No composer.lock file found, consider adding one to your repository to ensure reproducible builds.' + echo "In the meantime, a composer.lock file has been generated for you in $out/composer.lock" + echo + echo 'To fix the issue:' + echo "1. Copy the composer.lock file from $out/composer.lock to the project's source:" + echo " cp $out/composer.lock " + echo '2. Add the composerLock attribute, pointing to the copied composer.lock file:' + echo ' composerLock = ./composer.lock;' + echo + exit 1 fi echo "Validating consistency between composer.lock and ${composerRepository}/composer.lock" - if ! @diff@ composer.lock "${composerRepository}/composer.lock"; then + if [[! @diff@ composer.lock "${composerRepository}/composer.lock"]]; then echo echo "ERROR: vendorHash is out of date" echo diff --git a/pkgs/build-support/php/hooks/composer-repository-hook.sh b/pkgs/build-support/php/hooks/composer-repository-hook.sh index 5a923ddce212..779f07347548 100644 --- a/pkgs/build-support/php/hooks/composer-repository-hook.sh +++ b/pkgs/build-support/php/hooks/composer-repository-hook.sh @@ -17,7 +17,29 @@ composerRepositoryConfigureHook() { fi if [[ ! -f "composer.lock" ]]; then - echo "No composer.lock file found, consider adding one to your repository to ensure reproducible builds." + composer \ + --no-ansi \ + --no-install \ + --no-interaction \ + ${composerNoDev:+--no-dev} \ + ${composerNoPlugins:+--no-plugins} \ + ${composerNoScripts:+--no-scripts} \ + update + + mkdir -p $out + cp composer.lock $out/ + + echo + echo 'No composer.lock file found, consider adding one to your repository to ensure reproducible builds.' + echo "In the meantime, a composer.lock file has been generated for you in $out/composer.lock" + echo + echo 'To fix the issue:' + echo "1. Copy the composer.lock file from $out/composer.lock to the project's source:" + echo " cp $out/composer.lock " + echo '2. Add the composerLock attribute, pointing to the copied composer.lock file:' + echo ' composerLock = ./composer.lock;' + echo + exit 1 fi