From 6f5baab77b28b1d61837951ab9e5b33583f5a879 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 28 Dec 2021 21:31:52 +0100 Subject: [PATCH] Make COMPOSER_BIN_DIR env or _composer_bin_dir global available to binaries, fixes #10389 (#10402) --- src/Composer/Installer/BinaryInstaller.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Composer/Installer/BinaryInstaller.php b/src/Composer/Installer/BinaryInstaller.php index cb5b5deaf..f235a4474 100644 --- a/src/Composer/Installer/BinaryInstaller.php +++ b/src/Composer/Installer/BinaryInstaller.php @@ -231,12 +231,14 @@ class BinaryInstaller return "@ECHO OFF\r\n". "setlocal DISABLEDELAYEDEXPANSION\r\n". "SET BIN_TARGET=%~dp0/".trim(ProcessExecutor::escape(basename($link, '.bat')), '"\'')."\r\n". + "SET COMPOSER_BIN_DIR=%~dp0\r\n". "{$caller} \"%BIN_TARGET%\" %*\r\n"; } return "@ECHO OFF\r\n". "setlocal DISABLEDELAYEDEXPANSION\r\n". "SET BIN_TARGET=%~dp0/".trim(ProcessExecutor::escape($binPath), '"\'')."\r\n". + "SET COMPOSER_BIN_DIR=%~dp0\r\n". "{$caller} \"%BIN_TARGET%\" %*\r\n"; } @@ -260,14 +262,15 @@ class BinaryInstaller // carry over the existing shebang if present, otherwise add our own $proxyCode = empty($match[1]) ? '#!/usr/bin/env php' : trim($match[1]); $binPathExported = $this->filesystem->findShortestPathCode($link, $bin, false, true); - $autoloadPathCode = $streamProxyCode = $streamHint = ''; + $streamProxyCode = $streamHint = ''; + $globalsCode = '$GLOBALS[\'_composer_bin_dir\'] = __DIR__;'."\n"; // Don't expose autoload path when vendor dir was not set in custom installers if ($this->vendorDir) { - $autoloadPathCode = '$GLOBALS[\'_composer_autoload_path\'] = ' . $this->filesystem->findShortestPathCode($link, $this->vendorDir . '/autoload.php', false, true).";\n"; + $globalsCode .= '$GLOBALS[\'_composer_autoload_path\'] = ' . $this->filesystem->findShortestPathCode($link, $this->vendorDir . '/autoload.php', false, true).";\n"; } // Add workaround for PHPUnit process isolation on PHPUnit 6+ if ($this->filesystem->normalizePath($bin) === $this->filesystem->normalizePath($this->vendorDir.'/phpunit/phpunit/phpunit')) { - $autoloadPathCode .= '$GLOBALS[\'__PHPUNIT_ISOLATION_EXCLUDE_LIST\'] = $GLOBALS[\'__PHPUNIT_ISOLATION_BLACKLIST\'] = array(realpath('.$binPathExported.'));'."\n"; + $globalsCode .= '$GLOBALS[\'__PHPUNIT_ISOLATION_EXCLUDE_LIST\'] = $GLOBALS[\'__PHPUNIT_ISOLATION_BLACKLIST\'] = array(realpath('.$binPathExported.'));'."\n"; } if (trim($match[0]) !== ' /dev/null; pwd) + "\${dir}/$binFile" "\$@" PROXY;