Skip to content

Commit

Permalink
Merge pull request #285828 from drupol/php/remove-COMPOSER-ROOT-VERSI…
Browse files Browse the repository at this point in the history
…ON-env

build-support/php: set `COMPOSER_ROOT_VERSION` environment variable
  • Loading branch information
LeSuisse authored Feb 26, 2024
2 parents d8e0944 + ddb92f0 commit 3a19a72
Show file tree
Hide file tree
Showing 27 changed files with 17,399 additions and 662 deletions.
12 changes: 8 additions & 4 deletions pkgs/build-support/php/hooks/composer-install-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ preBuildHooks+=(composerInstallBuildHook)
preCheckHooks+=(composerInstallCheckHook)
preInstallHooks+=(composerInstallInstallHook)

source @phpScriptUtils@

composerInstallConfigureHook() {
echo "Executing composerInstallConfigureHook"

Expand All @@ -22,6 +24,8 @@ composerInstallConfigureHook() {
fi

if [[ ! -f "composer.lock" ]]; then
setComposeRootVersion

composer \
--no-ansi \
--no-install \
Expand Down Expand Up @@ -75,6 +79,8 @@ composerInstallConfigureHook() {
composerInstallBuildHook() {
echo "Executing composerInstallBuildHook"

setComposeRootVersion

# Since this file cannot be generated in the composer-repository-hook.sh
# because the file contains hardcoded nix store paths, we generate it here.
composer-local-repo-plugin --no-ansi build-local-repo -m "${composerRepository}" .
Expand All @@ -90,7 +96,6 @@ composerInstallBuildHook() {

# Since the composer.json file has been modified in the previous step, the
# composer.lock file needs to be updated.
COMPOSER_ROOT_VERSION="${version}" \
composer \
--lock \
--no-ansi \
Expand Down Expand Up @@ -134,11 +139,10 @@ composerInstallCheckHook() {
composerInstallInstallHook() {
echo "Executing composerInstallInstallHook"

setComposeRootVersion

# Finally, run `composer install` to install the dependencies and generate
# the autoloader.
# The COMPOSER_ROOT_VERSION environment variable is needed only for
# vimeo/psalm.
COMPOSER_ROOT_VERSION="${version}" \
composer \
--no-ansi \
--no-interaction \
Expand Down
7 changes: 6 additions & 1 deletion pkgs/build-support/php/hooks/composer-repository-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ preBuildHooks+=(composerRepositoryBuildHook)
preCheckHooks+=(composerRepositoryCheckHook)
preInstallHooks+=(composerRepositoryInstallHook)

source @phpScriptUtils@

composerRepositoryConfigureHook() {
echo "Executing composerRepositoryConfigureHook"

Expand All @@ -18,7 +20,8 @@ composerRepositoryConfigureHook() {
fi

if [[ ! -f "composer.lock" ]]; then
COMPOSER_ROOT_VERSION="${version}" \
setComposeRootVersion

composer \
--no-ansi \
--no-install \
Expand Down Expand Up @@ -55,6 +58,8 @@ composerRepositoryBuildHook() {

mkdir -p repository

setComposeRootVersion

# Build the local composer repository
# The command 'build-local-repo' is provided by the Composer plugin
# nix-community/composer-local-repo-plugin.
Expand Down
13 changes: 12 additions & 1 deletion pkgs/build-support/php/hooks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,28 @@
, makeSetupHook
, diffutils
, jq
, writeShellApplication
, moreutils
, makeBinaryWrapper
, cacert
, buildPackages
}:

let
php-script-utils = writeShellApplication {
name = "php-script-utils";
runtimeInputs = [ jq ];
text = builtins.readFile ./php-script-utils.bash;
};
in
{
composerRepositoryHook = makeSetupHook
{
name = "composer-repository-hook.sh";
propagatedBuildInputs = [ jq moreutils cacert ];
substitutions = { };
substitutions = {
phpScriptUtils = lib.getExe php-script-utils;
};
} ./composer-repository-hook.sh;

composerInstallHook = makeSetupHook
Expand All @@ -24,6 +34,7 @@
# Specify the stdenv's `diff` by abspath to ensure that the user's build
# inputs do not cause us to find the wrong `diff`.
cmp = "${lib.getBin buildPackages.diffutils}/bin/cmp";
phpScriptUtils = lib.getExe php-script-utils;
};
} ./composer-install-hook.sh;
}
12 changes: 12 additions & 0 deletions pkgs/build-support/php/hooks/php-script-utils.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
declare version

setComposeRootVersion() {
set +e # Disable exit on error

if [[ -v version ]]; then
echo -e "\e[32mSetting COMPOSER_ROOT_VERSION to $version\e[0m"
export COMPOSER_ROOT_VERSION=$version
fi

set -e
}
44 changes: 17 additions & 27 deletions pkgs/development/php-packages/deployer/default.nix
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
{ mkDerivation, fetchurl, makeWrapper, installShellFiles, lib, php }:
{ lib
, fetchFromGitHub
, php
}:

mkDerivation rec {
php.buildComposerProject (finalAttrs: {
pname = "deployer";
version = "6.8.0";
version = "7.3.3";

src = fetchurl {
url = "https://deployer.org/releases/v${version}/${pname}.phar";
sha256 = "09mxwfa7yszsiljbkxpsd4sghqngl08cn18v4g1fbsxp3ib3kxi5";
src = fetchFromGitHub {
owner = "deployphp";
repo = "deployer";
rev = "v${finalAttrs.version}^";
hash = "sha256-zvK7NwIACAhWN/7D8lVY1Bv8x6xKAp/L826SovQhDYg=";
};

dontUnpack = true;
vendorHash = "sha256-BDq2uryNWC31AEAEZJL9zGaAPbhXZ6hmfpsnr4wlixE=";

nativeBuildInputs = [ makeWrapper installShellFiles ];

installPhase = ''
runHook preInstall
mkdir -p $out/bin
install -D $src $out/libexec/deployer/deployer.phar
makeWrapper ${php}/bin/php $out/bin/dep --add-flags "$out/libexec/deployer/deployer.phar"
# fish support currently broken: https://github.com/deployphp/deployer/issues/2527
installShellCompletion --cmd dep \
--bash <($out/bin/dep autocomplete --install) \
--zsh <($out/bin/dep autocomplete --install)
runHook postInstall
'';

meta = with lib; {
description = "A deployment tool for PHP";
license = licenses.mit;
meta = {
description = "The PHP deployment tool with support for popular frameworks out of the box";
homepage = "https://deployer.org/";
license = lib.licenses.mit;
mainProgram = "dep";
maintainers = with maintainers; teams.php.members;
maintainers = lib.teams.php.members;
};
}
})
42 changes: 15 additions & 27 deletions pkgs/development/php-packages/phan/default.nix
Original file line number Diff line number Diff line change
@@ -1,42 +1,30 @@
{ lib
, fetchFromGitHub
, php
, mkDerivation
, fetchurl
, makeWrapper
}:
let
php' = php.withExtensions ({ enabled, all }: enabled ++ [ all.ast ]);
in
mkDerivation rec {

(php.withExtensions({ enabled, all }: enabled ++ (with all; [ ast ]))).buildComposerProject (finalAttrs: {
pname = "phan";
version = "5.4.3";

src = fetchurl {
url = "https://github.com/phan/phan/releases/download/${version}/phan.phar";
hash = "sha256-wZU6YIlH0q18iD044y6Z5gSscBn7cI0AwRwZgT/YhOo=";
src = fetchFromGitHub {
owner = "phan";
repo = "phan";
rev = finalAttrs.version;
hash = "sha256-O0dtnDsz6X99B99VbRQf3Wr/xJfsJqd+2l5Z5iWxHyU=";
};

dontUnpack = true;

nativeBuildInputs = [ makeWrapper ];

installPhase = ''
runHook preInstall
mkdir -p $out/bin
install -D $src $out/libexec/phan/phan.phar
makeWrapper ${php'}/bin/php $out/bin/phan \
--add-flags "$out/libexec/phan/phan.phar"
runHook postInstall
'';
vendorHash = "sha256-yE85MBseJa0VGV5EbjT0te4QT3697YvtumGkMMfZtxI=";

meta = with lib; {
meta = {
description = "Static analyzer for PHP";
homepage = "https://github.com/phan/phan";
license = lib.licenses.mit;
longDescription = ''
Phan is a static analyzer for PHP. Phan prefers to avoid false-positives
and attempts to prove incorrectness rather than correctness.
'';
license = licenses.mit;
homepage = "https://github.com/phan/phan";
maintainers = [ maintainers.apeschar ];
mainProgram = "phan";
maintainers = with lib.maintainers; [ apeschar ] ++ lib.teams.php.members;
};
}
})
Loading

0 comments on commit 3a19a72

Please sign in to comment.