[zorg] r345672 - Added support for getting the VC tools environment using vswhere.exe from VS 2017 if it exists.

Galina Kistanova via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 30 16:40:37 PDT 2018


Author: gkistanova
Date: Tue Oct 30 16:40:37 2018
New Revision: 345672

URL: http://llvm.org/viewvc/llvm-project?rev=345672&view=rev
Log:
Added support for getting the VC tools environment using vswhere.exe from VS 2017 if it exists.

Modified:
    zorg/trunk/zorg/buildbot/builders/Util.py

Modified: zorg/trunk/zorg/buildbot/builders/Util.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/zorg/buildbot/builders/Util.py?rev=345672&r1=345671&r2=345672&view=diff
==============================================================================
--- zorg/trunk/zorg/buildbot/builders/Util.py (original)
+++ zorg/trunk/zorg/buildbot/builders/Util.py Tue Oct 30 16:40:37 2018
@@ -1,11 +1,32 @@
 import buildbot.status.results
 import re
 
-def getVisualStudioEnvironment(vs=r"""%VS120COMNTOOLS%""", target_arch=None):
+def getVisualStudioEnvironment(vs=None, target_arch=None):
     # x86 builds should use the 64 bit -> x86 cross compilation toolchain to avoid
     # out of memory linker errors
     arch_arg = {'x86': 'amd64_x86', 'x64': 'amd64', 'amd64': 'amd64'}.get(target_arch, '%PROCESSOR_ARCHITECTURE%')
-    vcvars_command = "\"" + "\\".join((vs, '..','..','VC', 'vcvarsall.bat')) + "\""
+
+    if vs is None:
+        vs = r"""%VS120COMNTOOLS%""" # To keep the backward compatibility.
+
+    if vs.lower() == "autodetect":
+        """Get the VC tools environment using vswhere.exe from VS 2017 if it exists and was requested.
+        Otherwise, use the vs argument to construct a path to the expected location of vcvarsall.bat
+
+        This code is following the guidelines from strategy 1 in this blog post:
+        https://blogs.msdn.microsoft.com/vcblog/2017/03/06/finding-the-visual-c-compiler-tools-in-visual-studio-2017/
+
+        It doesn't work when VS is not installed at the default location.
+        """
+
+        # TODO: Implement autodetect for VS versions other than 2017
+        vcvars_command = "for /f \"tokens=* USEBACKQ\" %%F in " \
+                            "(`\"%ProgramFiles(x86)%\\Microsoft Visual Studio\\Installer\\vswhere.exe\" -latest -property installationPath`) DO " \
+                            "\"%%F\"\\VC\\Auxiliary\\Build\\vcvarsall.bat"
+    else:
+        # Older versions of VS
+        vcvars_command = "\"" + "\\".join((vs, '..','..','VC', 'vcvarsall.bat')) + "\""
+
     vcvars_command = "%s %s && set" % (vcvars_command, arch_arg)
     return vcvars_command
 




More information about the llvm-commits mailing list