From d8f1890b6fc0a1f378d8bb15731da5c5bada25d7 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 28 Dec 2021 15:41:40 +0100 Subject: [PATCH] Make COMPOSER_BIN_DIR env or _composer_bin_dir global available to binaries, fixes #10389 --- 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 cb5b5deaf8c1..f235a4474974 100644 --- a/src/Composer/Installer/BinaryInstaller.php +++ b/src/Composer/Installer/BinaryInstaller.php @@ -231,12 +231,14 @@ protected function generateWindowsProxyCode($bin, $link) 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 @@ protected function generateUnixyProxyCode($bin, $link) // 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;