[zorg] r345309 - [buildbot, windows] Update the way the visual studio environment is set

Stella Stamenova via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 25 13:30:09 PDT 2018


Author: stella.stamenova
Date: Thu Oct 25 13:30:08 2018
New Revision: 345309

URL: http://llvm.org/viewvc/llvm-project?rev=345309&view=rev
Log:
[buildbot, windows] Update the way the visual studio environment is set

Summary: 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

Reviewers: gkistanova

Reviewed By: gkistanova

Subscribers: asmith, llvm-commits

Differential Revision: https://reviews.llvm.org/D53158

Modified:
    zorg/trunk/buildbot/osuosl/master/config/builders.py
    zorg/trunk/zorg/buildbot/builders/ClangBuilder.py
    zorg/trunk/zorg/buildbot/builders/LLDBBuilder.py
    zorg/trunk/zorg/buildbot/builders/LLDBuilder.py
    zorg/trunk/zorg/buildbot/builders/SanitizerBuilderWindows.py
    zorg/trunk/zorg/buildbot/builders/UnifiedTreeBuilder.py
    zorg/trunk/zorg/buildbot/builders/Util.py

Modified: zorg/trunk/buildbot/osuosl/master/config/builders.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/buildbot/osuosl/master/config/builders.py?rev=345309&r1=345308&r2=345309&view=diff
==============================================================================
--- zorg/trunk/buildbot/osuosl/master/config/builders.py (original)
+++ zorg/trunk/buildbot/osuosl/master/config/builders.py Thu Oct 25 13:30:08 2018
@@ -994,6 +994,7 @@ def _get_lldb_builders():
          'factory': LLDBBuilder.getLLDBWindowsCMakeBuildFactory(
                     clean=True,
                     python_source_dir=r'"C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64"',
+                    autodetectVS=True,
                     target_arch='x64',
                     test=True,
                     extra_cmake_args=['-DLLVM_ENABLE_ASSERTIONS=OFF'])}

Modified: zorg/trunk/zorg/buildbot/builders/ClangBuilder.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/zorg/buildbot/builders/ClangBuilder.py?rev=345309&r1=345308&r2=345309&view=diff
==============================================================================
--- zorg/trunk/zorg/buildbot/builders/ClangBuilder.py (original)
+++ zorg/trunk/zorg/buildbot/builders/ClangBuilder.py Thu Oct 25 13:30:08 2018
@@ -461,6 +461,7 @@ def getClangCMakeGCSBuildFactory(
             # %VS120COMNTOOLS% selects the 2013 toolchain.
             vs=None,
             vs_target_arch='x86',
+            autodetectVS=False,
 
             # Multi-stage compilation
             useTwoStage=False,
@@ -496,8 +497,9 @@ def getClangCMakeGCSBuildFactory(
             # Triggers
             trigger_after_stage1=[]):
     return _getClangCMakeBuildFactory(
-               clean=clean, test=test, cmake=cmake, jobs=jobs, vs=vs,
-               vs_target_arch=vs_target_arch, useTwoStage=useTwoStage,
+               clean=clean, test=test, cmake=cmake, jobs=jobs,
+               vs=vs, vs_target_arch=vs_target_arch, autodetectVS=autodetectVS,
+               useTwoStage=useTwoStage,
                testStage1=testStage1, stage1_config=stage1_config,
                stage2_config=stage2_config, runTestSuite=runTestSuite,
                nt_flags=nt_flags, testsuite_flags=testsuite_flags,
@@ -522,6 +524,7 @@ def getClangCMakeBuildFactory(
             # %VS120COMNTOOLS% selects the 2013 toolchain.
             vs=None,
             vs_target_arch='x86',
+            autodetectVS=False,
 
             # Multi-stage compilation
             useTwoStage=False,
@@ -547,8 +550,9 @@ def getClangCMakeBuildFactory(
             checkout_libcxx=False,
             checkout_test_suite=False):
     return _getClangCMakeBuildFactory(
-               clean=clean, test=test, cmake=cmake, jobs=jobs, vs=vs,
-               vs_target_arch=vs_target_arch, useTwoStage=useTwoStage,
+               clean=clean, test=test, cmake=cmake, jobs=jobs,
+               vs=vs, vs_target_arch=vs_target_arch, autodetectVS=autodetectVS,
+               useTwoStage=useTwoStage,
                testStage1=testStage1, stage1_config=stage1_config,
                stage2_config=stage2_config, runTestSuite=runTestSuite,
                nt_flags=nt_flags, testsuite_flags=testsuite_flags,
@@ -570,6 +574,7 @@ def _getClangCMakeBuildFactory(
             # %VS120COMNTOOLS% selects the 2013 toolchain.
             vs=None,
             vs_target_arch='x86',
+            autodetectVS=False,
 
             # Multi-stage compilation
             useTwoStage=False,
@@ -637,9 +642,9 @@ def _getClangCMakeBuildFactory(
     stage2_install = 'stage2.install'
 
     # Set up VS environment, if appropriate.
-    if vs:
+    if vs or autodetectVS:
         f.addStep(SetProperty(
-            command=builders_util.getVisualStudioEnvironment(vs, vs_target_arch),
+            command=builders_util.getVisualStudioEnvironment(vs, vs_target_arch, autodetectVS),
             extract_fn=builders_util.extractSlaveEnvironment))
         assert not env, "Can't have custom builder env vars with VS"
         env = Property('slave_env')

Modified: zorg/trunk/zorg/buildbot/builders/LLDBBuilder.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/zorg/buildbot/builders/LLDBBuilder.py?rev=345309&r1=345308&r2=345309&view=diff
==============================================================================
--- zorg/trunk/zorg/buildbot/builders/LLDBBuilder.py (original)
+++ zorg/trunk/zorg/buildbot/builders/LLDBBuilder.py Thu Oct 25 13:30:08 2018
@@ -58,6 +58,7 @@ def getLLDBWindowsCMakeBuildFactory(
             vs=r"""%VS140COMNTOOLS%""",
             config='Release',
             target_arch='x86',
+            autodetectVS=False,
 
             extra_cmake_args=None,
             test=False,
@@ -68,7 +69,7 @@ def getLLDBWindowsCMakeBuildFactory(
 
     # Determine Slave Environment and Set MSVC environment.
     f.addStep(SetProperty(
-        command=getVisualStudioEnvironment(vs, target_arch),
+        command=getVisualStudioEnvironment(vs, target_arch, autodetectVS),
         extract_fn=extractSlaveEnvironment))
 
     f = getLLDBSource(f,'llvm')

Modified: zorg/trunk/zorg/buildbot/builders/LLDBuilder.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/zorg/buildbot/builders/LLDBuilder.py?rev=345309&r1=345308&r2=345309&view=diff
==============================================================================
--- zorg/trunk/zorg/buildbot/builders/LLDBuilder.py (original)
+++ zorg/trunk/zorg/buildbot/builders/LLDBuilder.py Thu Oct 25 13:30:08 2018
@@ -87,8 +87,9 @@ def getLLDWinBuildFactory(
            clean = True,
 
            # Default values for VS devenv and build configuration
-           vs = None,          # What to run to configure Visual Studio utils.
-           target_arch = None, # Native.
+           vs = None,            # What to run to configure Visual Studio utils.
+           autodetectVS = False, # Don't try to auto detect a VS installation.
+           target_arch = None,   # Native.
 
            extra_configure_args = None,
            env   = None):
@@ -119,9 +120,9 @@ def getLLDWinBuildFactory(
               ))
 
     # If set up environment step is requested, do this now.
-    if vs:
+    if vs or autodetectVS:
         f.addStep(SetProperty(
-            command=getVisualStudioEnvironment(vs, target_arch),
+            command=getVisualStudioEnvironment(vs, target_arch, autodetectVS),
             extract_fn=extractSlaveEnvironment))
         assert not env, "Can't have custom builder env vars with VS"
         env = Property('slave_env')

Modified: zorg/trunk/zorg/buildbot/builders/SanitizerBuilderWindows.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/zorg/buildbot/builders/SanitizerBuilderWindows.py?rev=345309&r1=345308&r2=345309&view=diff
==============================================================================
--- zorg/trunk/zorg/buildbot/builders/SanitizerBuilderWindows.py (original)
+++ zorg/trunk/zorg/buildbot/builders/SanitizerBuilderWindows.py Thu Oct 25 13:30:08 2018
@@ -41,6 +41,7 @@ def getSanitizerWindowsBuildFactory(
             vs=r"""%VS120COMNTOOLS%""",
             config='Release',
             target_arch='x86',
+            autodetectVS=False,
 
             extra_cmake_args=[]):
 
@@ -59,7 +60,7 @@ def getSanitizerWindowsBuildFactory(
 
     # Determine Slave Environment and Set MSVC environment.
     f.addStep(SetProperty(
-        command=getVisualStudioEnvironment(vs, target_arch),
+        command=getVisualStudioEnvironment(vs, target_arch, autodetectVS),
         extract_fn=extractSlaveEnvironment))
 
     f = getSource(f,'llvm')

Modified: zorg/trunk/zorg/buildbot/builders/UnifiedTreeBuilder.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/zorg/buildbot/builders/UnifiedTreeBuilder.py?rev=345309&r1=345308&r2=345309&view=diff
==============================================================================
--- zorg/trunk/zorg/buildbot/builders/UnifiedTreeBuilder.py (original)
+++ zorg/trunk/zorg/buildbot/builders/UnifiedTreeBuilder.py Thu Oct 25 13:30:08 2018
@@ -273,6 +273,7 @@ def getCmakeWithNinjaWithMSVCBuildFactor
            # %VS140COMNTOOLS% selects the 2015 toolchain.
            vs=None,
            target_arch=None,
+           autodetectVS=False,
            env = None,
            **kwargs):
 
@@ -300,7 +301,7 @@ def getCmakeWithNinjaWithMSVCBuildFactor
             **kwargs) # Pass through all the extra arguments.
 
     f.addStep(SetProperty(
-        command=builders_util.getVisualStudioEnvironment(vs, target_arch),
+        command=builders_util.getVisualStudioEnvironment(vs, target_arch, autodetectVS),
         extract_fn=builders_util.extractSlaveEnvironment))
     env = Property('slave_env')
 

Modified: zorg/trunk/zorg/buildbot/builders/Util.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/zorg/buildbot/builders/Util.py?rev=345309&r1=345308&r2=345309&view=diff
==============================================================================
--- zorg/trunk/zorg/buildbot/builders/Util.py (original)
+++ zorg/trunk/zorg/buildbot/builders/Util.py Thu Oct 25 13:30:08 2018
@@ -1,11 +1,33 @@
 import buildbot.status.results
+import os
 import re
+import subprocess
 
-def getVisualStudioEnvironment(vs=r"""%VS120COMNTOOLS%""", target_arch=None):
+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, autodetectVS=False):
     # 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 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.
+    """
+    # Use vswhere.exe if it exists.
+    if autodetectVS and 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
 




More information about the llvm-commits mailing list