From bdd4a814f9b09e88f0005e891f2cb995ed664753 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Mon, 11 May 2020 23:27:18 +0100 Subject: [PATCH] Activate MSVC during CMake setup for NMake --- CI/before_script.msvc.sh | 55 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/CI/before_script.msvc.sh b/CI/before_script.msvc.sh index 1d5df08a92..a64dbe503f 100644 --- a/CI/before_script.msvc.sh +++ b/CI/before_script.msvc.sh @@ -33,7 +33,20 @@ function unixPathAsWindows { cygpath -w $1 else echo "$1" | sed "s,^/\([^/]\)/,\\1:/," | sed "s,/,\\\\,g" + 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 } @@ -54,6 +67,8 @@ CONFIGURATION="" TEST_FRAMEWORK="" GOOGLE_INSTALL_ROOT="" +ACTIVATE_MSVC="" + while [ $# -gt 0 ]; do ARGSTR=$1 shift @@ -139,7 +154,7 @@ EOF done if [ -n "$NMAKE" ]; then - command -v nmake -? >/dev/null 2>&1 || { echo "Error: nmake (NMake) is not on the path. Make sure you have the necessary environment variables set for command-line C++ development (for example, by starting from a Developer Command Prompt)."; exit 1; } + ACTIVATE_MSVC=true fi if [ -z $VERBOSE ]; then @@ -385,6 +400,44 @@ echo "Starting prebuild on MSVC${MSVC_DISPLAY_YEAR} WIN${BITS}" echo "===================================" echo +if ! [ -z $ACTIVATE_MSVC ]; then + echo "Activating MSVC in the current shell." + command -v vswhere >/dev/null 2>&1 || { echo "Error: vswhere is not on the path."; exit 1; } + + # 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}" + originalCmdEnv["${separatedPair[0]}"]="${separatedPair[1]}" + done + + MSVC_INSTALLATION_PATH=$(vswhere -legacy -version $MSVC_VER -property installationPath) + # capture CMD environment in a shell with MSVC activated + if [ $MSVC_REAL_VER -ge 15 ]; then + cmdEnv="$(cmd //c "${MSVC_INSTALLATION_PATH}\Common7\Tools\VsDevCmd.bat" -no_logo -arch=$([ $BITS -eq 64 ] && echo "amd64" || echo "x86") -host_arch=$([ $(uname -m) == 'x86_64' ] && echo "amd64" || echo "x86") "&&" set)" + else + echo "MSVC 2015 and older not yet supported" + exit 1 + fi + + declare -A cmdEnvChanges + for pair in $cmdEnv; do + IFS='=' read -r -a separatedPair <<< "${pair}" + 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 + done + IFS="$originalIFS" +fi + # cd OpenMW/AppVeyor-test mkdir -p deps cd deps