From 2dbd86ae23fa4f77ecbbbceabb39d765849d571c Mon Sep 17 00:00:00 2001 From: gibbed Date: Thu, 18 Apr 2019 10:14:18 -0500 Subject: [PATCH] Rework Xenia/premake build scripts to use VsDevCmd for VS2017+ instead of vcvarsall.bat, this removes Windows Universal CRT SDK as a required dependency. --- tools/build/premake | 48 ++++++++++++++++++++++++--------------------- xenia-build | 48 ++++++++++++++++++++++++--------------------- 2 files changed, 52 insertions(+), 44 deletions(-) diff --git a/tools/build/premake b/tools/build/premake index c4c471d99..ceb72db72 100644 --- a/tools/build/premake +++ b/tools/build/premake @@ -139,33 +139,40 @@ def import_vs_environment(): interesting environment variables into os.environ. 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 + 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) - candidate_path = candidate_path.strip() + vswhere = subprocess.check_output('third_party/vswhere/vswhere.exe -version "[15,)" -latest -format json', shell=False, universal_newlines=True) + 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: 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( - 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() envvars_to_save = ( 'devenvdir', @@ -188,9 +195,6 @@ def import_vs_environment(): os.environ[var.upper()] = setting break - os.environ['VSVERSION'] = str(version) - return version - def git_submodule_update(): """Runs a full recursive git submodule init and update. diff --git a/xenia-build b/xenia-build index c863ccfb7..4409bb2b6 100755 --- a/xenia-build +++ b/xenia-build @@ -9,6 +9,7 @@ Run with --help or no arguments for possible commands. from __future__ import print_function import argparse +import json import os import re import shutil @@ -89,31 +90,38 @@ def import_vs_environment(): interesting environment variables into os.environ. 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 + 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) - candidate_path = candidate_path.strip() + vswhere = subprocess.check_output('third_party/vswhere/vswhere.exe -version "[15,)" -latest -format json', shell=False, universal_newlines=True) + 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: 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( args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) variables, _ = popen.communicate() @@ -138,10 +146,6 @@ def import_vs_environment(): os.environ[var.upper()] = setting break - os.environ['VSVERSION'] = str(version) - return version - - def has_bin(binary): """Checks whether the given binary is present.