bug 1318143 - add a --with-visual-studio-version to choose which VS version configure chooses when multiple versions are installed. r?gps draft
authorTed Mielczarek <ted@mielczarek.org>
Thu, 20 Apr 2017 12:43:44 -0400
changeset 567651 060c4abbb28d6862f078e891cbf909f2299f28b9
parent 567650 c47f782a4e88539fcfa148fd5f098f9d8428dabf
child 625725 22e1f7b2d89f215ba000d0023ffedd48ac5557ba
push id55652
push userbmo:ted@mielczarek.org
push dateTue, 25 Apr 2017 10:36:45 +0000
reviewersgps
bugs1318143
milestone55.0a1
bug 1318143 - add a --with-visual-studio-version to choose which VS version configure chooses when multiple versions are installed. r?gps MozReview-Commit-ID: C6IoZJNHR4G
build/moz.configure/toolchain.configure
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -431,33 +431,50 @@ def get_vc_paths(topsrcdir):
         tools_version = open(os.path.join(path, r'VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt'), 'rb').read().strip()
         tools_path = os.path.join(path, r'VC\Tools\MSVC', tools_version, r'bin\HostX64')
         yield (Version(install['installationVersion']), {
             'x64': [os.path.join(tools_path, 'x64')],
             # The x64->x86 cross toolchain requires DLLs from the native x64 toolchain.
             'x86': [os.path.join(tools_path, 'x86'), os.path.join(tools_path, 'x64')],
         })
 
+option('--with-visual-studio-version', nargs=1,
+       choices=('2015', '2017'),
+       help='Select a specific Visual Studio version to use')
 
-@depends(host, target, check_build_environment)
+@depends('--with-visual-studio-version')
+def vs_major_version(value):
+    if value:
+        return {'2015': 14,
+                '2017': 15}[value[0]]
+
+@depends(host, target, vs_major_version, check_build_environment, '--with-visual-studio-version')
 @imports(_from='__builtin__', _import='sorted')
 @imports(_from='operator', _import='itemgetter')
 @imports('platform')
-def vc_compiler_path(host, target, env):
+def vc_compiler_path(host, target, vs_major_version, env, vs_release_name):
     if host.kernel != 'WINNT':
         return
     vc_target = {
         'x86': 'x86',
         'x86_64': 'x64',
         'arm': 'arm',
     }.get(target.cpu)
     if vc_target is None:
         return
 
-    version, data = sorted(get_vc_paths(env.topsrcdir), key=itemgetter(0))[-1]
+    all_versions = sorted(get_vc_paths(env.topsrcdir), key=itemgetter(0))
+    if vs_major_version:
+        versions = [d for (v, d) in all_versions if v.major == vs_major_version]
+        if not versions:
+            die('Visual Studio %s could not be found!' % vs_release_name)
+        data = versions[0]
+    else:
+        # Choose the newest version.
+        data = all_versions[-1][1]
     paths = data.get(vc_target)
     if not paths:
         return
     return paths
 
 
 @depends(vc_compiler_path)
 @imports('os')