Forráskód Böngészése

generateUnixyProxyCode() properly supporting Cygwin & Git Bash

Based on Composer's proxy: https://github.com/composer/windows-setup/blob/master/src/shims/composer
Grzegorz 'Wirone' Korba 11 éve
szülő
commit
0558bf0079
1 módosított fájl, 24 hozzáadás és 8 törlés
  1. 24 8
      src/Composer/Installer/LibraryInstaller.php

+ 24 - 8
src/Composer/Installer/LibraryInstaller.php

@@ -303,13 +303,29 @@ class LibraryInstaller implements InstallerInterface
     protected function generateUnixyProxyCode($bin, $link)
     {
         $binPath = $this->filesystem->findShortestPath($link, $bin);
-
-        return "#!/usr/bin/env sh\n".
-            'SRC_DIR="`pwd`"'."\n".
-            'cd "`dirname "$0"`"'."\n".
-            'cd '.escapeshellarg(dirname($binPath))."\n".
-            'BIN_TARGET="`pwd`/'.basename($binPath)."\"\n".
-            'cd "$SRC_DIR"'."\n".
-            '"$BIN_TARGET" "$@"'."\n";
+        $binDir = escapeshellarg(dirname($binPath));
+        $binFile = basename($binPath);
+
+        $proxyCode = <<<PROXY
+#!/bin/sh
+
+dir=$(d=$(dirname "$0"); cd "\$d"; cd $binDir && pwd)
+
+# see if we are running in cygwin by checking for cygpath program
+if command -v 'cygpath' >/dev/null 2>&1; then
+	# cygwin paths start with /cygdrive/ which will break windows PHP,
+	# so we need to translate the dir path to windows format. However
+	# we could be using cygwin PHP which does not require this, so we
+	# test if the path to PHP starts with /cygdrive/ rather than /usr/bin.
+	if [[ $(which php) == /cygdrive/* ]]; then
+		dir=$(cygpath -m \$dir);
+	fi
+fi
+
+dir=$(echo \$dir | sed 's/ /\ /g')
+"\${dir}/$binFile" "$@"
+PROXY;
+
+        return $proxyCode;
     }
 }