From a8c5fc74d1cf431522d40758e7600b6465c6529f Mon Sep 17 00:00:00 2001
From: AnyOldName3 <krizdjali+gitlab@gmail.com>
Date: Wed, 28 Apr 2021 06:51:15 +0000
Subject: [PATCH] Massively simplify the worst Bash ever

---
 CI/activate_msvc.sh | 54 ++++-----------------------------------------
 1 file changed, 4 insertions(+), 50 deletions(-)

diff --git a/CI/activate_msvc.sh b/CI/activate_msvc.sh
index 47f2c246f0..233f017433 100644
--- a/CI/activate_msvc.sh
+++ b/CI/activate_msvc.sh
@@ -30,55 +30,11 @@ command -v unixPathAsWindows >/dev/null 2>&1 || function unixPathAsWindows {
 	fi
 }
 
-function windowsSystemPathAsUnix {
-	if command -v cygpath >/dev/null 2>&1; then
-		cygpath -u -p $1
-	else
-		IFS=';' read -r -a paths <<< "$1"
-		declare -a convertedPaths
-		for entry in paths; do
-			convertedPaths+=(windowsPathAsUnix $entry)
-		done
-		convertedPath=printf ":%s" ${convertedPaths[@]}
-		echo ${convertedPath:1}
-	fi
-}
-
-# capture CMD environment so we know what's been changed
-declare -A originalCmdEnv
-originalIFS="$IFS"
-IFS=$'\n\r'
-for pair in $(cmd //c "set"); do
-    IFS='=' read -r -a separatedPair <<< "${pair}"
-    if [ ${#separatedPair[@]} -ne 2 ]; then
-        echo "Parsed '$pair' as ${#separatedPair[@]} parts, expected 2."
-        continue
-    fi
-    originalCmdEnv["${separatedPair[0]}"]="${separatedPair[1]}"
-done
 
 # capture CMD environment in a shell with MSVC activated
-cmdEnv="$(cmd //c "$(unixPathAsWindows "$(dirname "${BASH_SOURCE[0]}")")\ActivateMSVC.bat" "&&" set)"
-
-declare -A cmdEnvChanges
-for pair in $cmdEnv; do
-    if [ -n "$pair" ]; then
-        IFS='=' read -r -a separatedPair <<< "${pair}"
-        if [ ${#separatedPair[@]} -ne 2 ]; then
-            echo "Parsed '$pair' as ${#separatedPair[@]} parts, expected 2."
-            continue
-        fi
-        key="${separatedPair[0]}"
-        value="${separatedPair[1]}"
-        if ! [ ${originalCmdEnv[$key]+_} ] || [ "${originalCmdEnv[$key]}" != "$value" ]; then
-            if [ $key != 'PATH' ] && [ $key != 'path' ] && [ $key != 'Path' ]; then
-                export "$key=$value"
-            else
-                export PATH=$(windowsSystemPathAsUnix $value)
-            fi
-        fi
-    fi
-done
+cmd //c "$(unixPathAsWindows "$(dirname "${BASH_SOURCE[0]}")")\ActivateMSVC.bat" "&&" "bash" "-c" "declare -px > declared_env.sh"
+source ./declared_env.sh
+rm declared_env.sh
 
 MISSINGTOOLS=0
 
@@ -93,6 +49,4 @@ if [ $MISSINGTOOLS -ne 0 ]; then
     return 1
 fi
 
-IFS="$originalIFS"
-
-restoreOldSettings
\ No newline at end of file
+restoreOldSettings