[PATCH] D53158: [buildbot, windows] Update the way the visual studio environment is set

Stella Stamenova via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 11 12:00:16 PDT 2018


stella.stamenova created this revision.
stella.stamenova added a reviewer: gkistanova.
Herald added a subscriber: llvm-commits.

With vs2017 there were several changes to the installation paths for VS including the vcvarsall.bat script used for setting the environment. To correctly get the paths for the newer versions of VS, we should use vswhere instead. This is similar to how the annotated builder sets the environment as well


Repository:
  rL LLVM

https://reviews.llvm.org/D53158

Files:
  zorg/buildbot/builders/Util.py


Index: zorg/buildbot/builders/Util.py
===================================================================
--- zorg/buildbot/builders/Util.py
+++ zorg/buildbot/builders/Util.py
@@ -1,11 +1,32 @@
 import buildbot.status.results
+import os
 import re
+import subprocess
+
+from os.path import join as pjoin
+
+VSWHERE_PATH = "C:/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe"
 
 def getVisualStudioEnvironment(vs=r"""%VS120COMNTOOLS%""", 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')) + "\""
+
+    """Get the VC tools environment using vswhere.exe from VS 2017 if it exists or the vs argument otherwise
+
+    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.
+    """
+    # Use vswhere.exe if it exists.
+    if os.path.exists(VSWHERE_PATH):
+        cmd = [VSWHERE_PATH, "-latest", "-property", "installationPath"]
+        vs_path = subprocess.check_output(cmd).strip()
+        vcvars_command = pjoin(vs_path, 'VC', 'Auxiliary', 'Build', 'vcvarsall.bat')
+    else:
+        vcvars_command = "\"" + "\\".join((vs, '..','..','VC', 'vcvarsall.bat')) + "\""
+
     vcvars_command = "%s %s && set" % (vcvars_command, arch_arg)
     return vcvars_command
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53158.169265.patch
Type: text/x-patch
Size: 1675 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181011/c185dde7/attachment.bin>


More information about the llvm-commits mailing list