Index: zorg/trunk/buildbot/osuosl/master/config/builders.py =================================================================== --- zorg/trunk/buildbot/osuosl/master/config/builders.py +++ zorg/trunk/buildbot/osuosl/master/config/builders.py @@ -994,6 +994,7 @@ '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'])} Index: zorg/trunk/zorg/buildbot/builders/ClangBuilder.py =================================================================== --- zorg/trunk/zorg/buildbot/builders/ClangBuilder.py +++ zorg/trunk/zorg/buildbot/builders/ClangBuilder.py @@ -461,6 +461,7 @@ # %VS120COMNTOOLS% selects the 2013 toolchain. vs=None, vs_target_arch='x86', + autodetectVS=False, # Multi-stage compilation useTwoStage=False, @@ -496,8 +497,9 @@ # 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 @@ # %VS120COMNTOOLS% selects the 2013 toolchain. vs=None, vs_target_arch='x86', + autodetectVS=False, # Multi-stage compilation useTwoStage=False, @@ -547,8 +550,9 @@ 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 @@ # %VS120COMNTOOLS% selects the 2013 toolchain. vs=None, vs_target_arch='x86', + autodetectVS=False, # Multi-stage compilation useTwoStage=False, @@ -637,9 +642,9 @@ 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') Index: zorg/trunk/zorg/buildbot/builders/LLDBBuilder.py =================================================================== --- zorg/trunk/zorg/buildbot/builders/LLDBBuilder.py +++ zorg/trunk/zorg/buildbot/builders/LLDBBuilder.py @@ -58,6 +58,7 @@ vs=r"""%VS140COMNTOOLS%""", config='Release', target_arch='x86', + autodetectVS=False, extra_cmake_args=None, test=False, @@ -68,7 +69,7 @@ # 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') Index: zorg/trunk/zorg/buildbot/builders/LLDBuilder.py =================================================================== --- zorg/trunk/zorg/buildbot/builders/LLDBuilder.py +++ zorg/trunk/zorg/buildbot/builders/LLDBuilder.py @@ -87,8 +87,9 @@ 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 @@ )) # 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') Index: zorg/trunk/zorg/buildbot/builders/SanitizerBuilderWindows.py =================================================================== --- zorg/trunk/zorg/buildbot/builders/SanitizerBuilderWindows.py +++ zorg/trunk/zorg/buildbot/builders/SanitizerBuilderWindows.py @@ -41,6 +41,7 @@ vs=r"""%VS120COMNTOOLS%""", config='Release', target_arch='x86', + autodetectVS=False, extra_cmake_args=[]): @@ -59,7 +60,7 @@ # 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') Index: zorg/trunk/zorg/buildbot/builders/UnifiedTreeBuilder.py =================================================================== --- zorg/trunk/zorg/buildbot/builders/UnifiedTreeBuilder.py +++ zorg/trunk/zorg/buildbot/builders/UnifiedTreeBuilder.py @@ -273,6 +273,7 @@ # %VS140COMNTOOLS% selects the 2015 toolchain. vs=None, target_arch=None, + autodetectVS=False, env = None, **kwargs): @@ -300,7 +301,7 @@ **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') Index: zorg/trunk/zorg/buildbot/builders/Util.py =================================================================== --- zorg/trunk/zorg/buildbot/builders/Util.py +++ zorg/trunk/zorg/buildbot/builders/Util.py @@ -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