Skip to content

Instantly share code, notes, and snippets.

@mulle-nat
Created January 26, 2023 22:21
Show Gist options
  • Save mulle-nat/8868f86227125f6eff14497da7baa6f1 to your computer and use it in GitHub Desktop.
Save mulle-nat/8868f86227125f6eff14497da7baa6f1 to your computer and use it in GitHub Desktop.
Convert Visual Studio environment variables to bash for use in mingw (also run in mingw)
#! /usr/bin/env bash
#
# Copyright (c) 2023 Nat! - Mulle kybernetiK
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# Neither the name of Mulle kybernetiK nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#
# This script is for use in MINGW. Grabs the environment variables you need from
# VS Studio prompt and adds them to your mulle-sde environment.
#
OUTPUT_FORMAT="${1:-echo}"
echo "Provide the output of \"set\" from the \"Native Tools Command Prompt for VS\" as stdin..." >&2
settings="`grep -E 'Visual\ Studio|WindowsSDK' `"
r_convert_path()
{
RVAL=
old="${IFS}"
IFS=";"
for item in $1
do
if [ -z "${item}" ]
then
continue
fi
converted="`cygpath.exe "${item}" `"
if [ -z "${RVAL}" ]
then
RVAL="${converted}"
else
RVAL="${RVAL}:${converted}"
fi
done
IFS="${old}"
}
set -f
IFS=$'\n'
for line in ${settings}
do
key="${line%%=*}"
value="${line#*=}"
# convert multipath or singlepath
case "${value}" in
*:\\*\;*)
r_convert_path "${value}"
value="${RVAL}"
;;
*:\\*)
value="`cygpath.exe "${value}"`"
;;
# for WindowsSDKVersion and WindowsSDKLibVersion, hmmm
*\\)
value="${value//\\//}"
;;
esac
case "${key}" in
Path)
key='PATH'
value="${value}:\${PATH}"
;;
esac
# escape for output (or use printf -q)
value="${value//\"/\\\"}"
case "${OUTPUT_FORMAT}" in
echo)
echo "${key}=\"${value}\""
;;
mulle-sde-echo)
echo mulle-sde environment --this-os set "${key}" "\"${value}\""
;;
mulle-sde)
# could, should use mset here
mulle-sde environment --this-os set "${key}" "${value}"
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment