From d2c84e37ee591b0be2b7406d001d3a9f061584b9 Mon Sep 17 00:00:00 2001 From: gibbed Date: Wed, 19 Apr 2017 21:31:30 -0500 Subject: [PATCH] Use vswhere to detect Visual Studio 2017. --- xenia-build | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/xenia-build b/xenia-build index f1415195e..ae0914ae0 100755 --- a/xenia-build +++ b/xenia-build @@ -48,8 +48,9 @@ def main(): # Grab Visual Studio version and execute shell to set up environment. if sys.platform == 'win32': vs_version = import_vs_environment() - if vs_version != 2015: - print('ERROR: Visual Studio 2015 not found!') + if vs_version == 0: + print('ERROR: Visual Studio not found!') + print('Visual Studio 2015 is the recommended version.') print('Ensure you have the VS140COMNTOOLS environment variable!') sys.exit(1) return @@ -98,15 +99,23 @@ def import_vs_environment(): A version such as 2015 or None if no VS is found. """ version = 0 + + candidate_path = subprocess.check_output('third_party/vswhere/vswhere.exe -version "[15,)" -latest -format value -property installationPath', shell=False); + candidate_path = candidate_path.strip() + tools_path = '' - if 'VS140COMNTOOLS' in os.environ: + 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 = 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 - tools_path = os.path.join(tools_path, '..\\..\\vc\\vcvarsall.bat') - args = [tools_path, '&&', 'set'] + args = [tools_path, 'x64', '&&', 'set'] popen = subprocess.Popen( args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) variables, _ = popen.communicate()