Rework Xenia/premake build scripts to use VsDevCmd for VS2017+ instead

of vcvarsall.bat, this removes Windows Universal CRT SDK as a required
dependency.
This commit is contained in:
gibbed 2019-04-18 10:14:18 -05:00
parent 593a871c84
commit 2dbd86ae23
2 changed files with 52 additions and 44 deletions

View File

@ -139,33 +139,40 @@ def import_vs_environment():
interesting environment variables into os.environ. interesting environment variables into os.environ.
Returns: Returns:
A version such as 2015 or None if no VS is found. A version such as 2015 or None if no installation is found.
""" """
version = 0 version = 0
install_path = None
env_tool_args = None
candidate_path = subprocess.check_output('../../third_party/vswhere/vswhere.exe -all -version "[15,)" -latest -format value -property installationPath', shell=False, universal_newlines=True) vswhere = subprocess.check_output('third_party/vswhere/vswhere.exe -version "[15,)" -latest -format json', shell=False, universal_newlines=True)
candidate_path = candidate_path.strip() if vswhere:
vswhere = json.loads(vswhere)
if vswhere and len(vswhere) > 0:
version = int(vswhere[0].get("catalog", {}).get("productLineVersion", 2017))
install_path = vswhere[0].get("installationPath", None)
if version < 2017:
if 'VS140COMNTOOLS' in os.environ:
version = 2015
vcvars_path = os.environ['VS140COMNTOOLS']
vcvars_path = os.path.join(tools_path, '..\\..\\vc\\vcvarsall.bat')
env_tool_args = [vcvars_path, 'x64', '&&', 'set']
else:
vsdevcmd_path = os.path.join(install_path, 'Common7\\Tools\\VsDevCmd.bat')
env_tool_args = [vsdevcmd_path, '-arch=amd64', '-host_arch=amd64']
tools_path = ''
if candidate_path:
tools_path = os.path.join(candidate_path, 'vc\\auxiliary\\build\\vcvarsall.bat')
if os.path.isfile(tools_path) and os.access(tools_path, os.X_OK):
version = subprocess.check_output('../../third_party/vswhere/vswhere.exe -version "[15,)" -latest -format value -property catalog_productLineVersion', shell=False, universal_newlines=True)
version = version.strip()
if version:
version = int(version)
else:
version = 2017
if version == 0 and 'VS140COMNTOOLS' in os.environ:
version = 2015
tools_path = os.environ['VS140COMNTOOLS']
tools_path = os.path.join(tools_path, '..\\..\\vc\\vcvarsall.bat')
if version == 0: if version == 0:
return None return None
args = [tools_path, 'x64', '&&', 'set'] import_subprocess_environment(env_tool_args)
os.environ['VSVERSION'] = str(version)
return version
def import_subprocess_environment(args):
popen = subprocess.Popen( popen = subprocess.Popen(
args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
variables, _ = popen.communicate() variables, _ = popen.communicate()
envvars_to_save = ( envvars_to_save = (
'devenvdir', 'devenvdir',
@ -188,9 +195,6 @@ def import_vs_environment():
os.environ[var.upper()] = setting os.environ[var.upper()] = setting
break break
os.environ['VSVERSION'] = str(version)
return version
def git_submodule_update(): def git_submodule_update():
"""Runs a full recursive git submodule init and update. """Runs a full recursive git submodule init and update.

View File

@ -9,6 +9,7 @@ Run with --help or no arguments for possible commands.
from __future__ import print_function from __future__ import print_function
import argparse import argparse
import json
import os import os
import re import re
import shutil import shutil
@ -89,31 +90,38 @@ def import_vs_environment():
interesting environment variables into os.environ. interesting environment variables into os.environ.
Returns: Returns:
A version such as 2015 or None if no VS is found. A version such as 2015 or None if no installation is found.
""" """
version = 0 version = 0
install_path = None
env_tool_args = None
candidate_path = subprocess.check_output('third_party/vswhere/vswhere.exe -version "[15,)" -latest -format value -property installationPath', shell=False, universal_newlines=True) vswhere = subprocess.check_output('third_party/vswhere/vswhere.exe -version "[15,)" -latest -format json', shell=False, universal_newlines=True)
candidate_path = candidate_path.strip() if vswhere:
vswhere = json.loads(vswhere)
if vswhere and len(vswhere) > 0:
version = int(vswhere[0].get("catalog", {}).get("productLineVersion", 2017))
install_path = vswhere[0].get("installationPath", None)
if version < 2017:
if 'VS140COMNTOOLS' in os.environ:
version = 2015
vcvars_path = os.environ['VS140COMNTOOLS']
vcvars_path = os.path.join(tools_path, '..\\..\\vc\\vcvarsall.bat')
env_tool_args = [vcvars_path, 'x64', '&&', 'set']
else:
vsdevcmd_path = os.path.join(install_path, 'Common7\\Tools\\VsDevCmd.bat')
env_tool_args = [vsdevcmd_path, '-arch=amd64', '-host_arch=amd64']
tools_path = ''
if candidate_path:
tools_path = os.path.join(candidate_path, 'vc\\auxiliary\\build\\vcvarsall.bat')
if os.path.isfile(tools_path) and os.access(tools_path, os.X_OK):
version = subprocess.check_output('third_party/vswhere/vswhere.exe -version "[15,)" -latest -format value -property catalog_productLineVersion', shell=False, universal_newlines=True)
version = version.strip()
if version:
version = int(version)
else:
version = 2017
if version == 0 and 'VS140COMNTOOLS' in os.environ:
version = 2015
tools_path = os.environ['VS140COMNTOOLS']
tools_path = os.path.join(tools_path, '..\\..\\vc\\vcvarsall.bat')
if version == 0: if version == 0:
return None return None
args = [tools_path, 'x64', '&&', 'set'] import_subprocess_environment(env_tool_args)
os.environ['VSVERSION'] = str(version)
return version
def import_subprocess_environment(args):
popen = subprocess.Popen( popen = subprocess.Popen(
args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
variables, _ = popen.communicate() variables, _ = popen.communicate()
@ -138,10 +146,6 @@ def import_vs_environment():
os.environ[var.upper()] = setting os.environ[var.upper()] = setting
break break
os.environ['VSVERSION'] = str(version)
return version
def has_bin(binary): def has_bin(binary):
"""Checks whether the given binary is present. """Checks whether the given binary is present.