Merge branch 'msvc_detect' into 'master'

msvc: fix version detection when new and old compilers are installed

Closes #2352

See merge request ita1024/waf!2340
This commit is contained in:
Alibek Omarov 2022-05-18 22:44:29 +00:00
commit 06a661ef49
2 changed files with 38 additions and 1 deletions

25
tests/msvc/wscript Executable file
View File

@ -0,0 +1,25 @@
#! /usr/bin/env python3.1
from waflib.Tools import msvc
from waflib import Logs
def configure(ctx):
pass
def test(ctx):
errors = []
msvc_versions = ['wsdk 6.1', 'winphone 8.0', 'msvc 9.0', 'msvc 16.6', 'msvc 16.0', 'msvc 15.9', 'msvc 15.0', 'msvc 14.0', 'msvc 12.0', 'msvc 11.0']
sorted_versions = ['wsdk 6.1', 'winphone 8.0', 'msvc 16.6', 'msvc 16.0', 'msvc 15.9', 'msvc 15.0', 'msvc 14.0', 'msvc 12.0', 'msvc 11.0', 'msvc 9.0']
def tt(msg, result, expected):
color = 'RED'
if result == expected:
color = 'GREEN'
else:
errors.append(result)
Logs.pprint(color, msg.ljust(20) + " %r" % result)
tt('msvc version detection sort', sorted(msvc_versions, key=msvc.MSVCVersion, reverse=True), sorted_versions)
if errors:
ctx.fatal('There are test failures')

View File

@ -109,6 +109,16 @@ def options(opt):
opt.add_option('--msvc_targets', type='string', help = 'msvc targets, eg: "x64,arm"', default='')
opt.add_option('--no-msvc-lazy', action='store_false', help = 'lazily check msvc target environments', default=True, dest='msvc_lazy')
class MSVCVersion:
def __init__(self, ver):
x = ver.split()
self.a = x[0]
self.b = float(x[1])
def __lt__(self, other):
if self.a == other.a: return self.b < other.b
return self.a < other.a
@conf
def setup_msvc(conf, versiondict):
"""
@ -125,7 +135,9 @@ def setup_msvc(conf, versiondict):
platforms=Utils.to_list(conf.env.MSVC_TARGETS) or [i for i,j in all_msvc_platforms+all_icl_platforms+all_wince_platforms]
desired_versions = getattr(Options.options, 'msvc_version', '').split(',')
if desired_versions == ['']:
desired_versions = conf.env.MSVC_VERSIONS or list(reversed(sorted(versiondict.keys())))
def versionkey(x):
return float(x.split()[1])
desired_versions = conf.env.MSVC_VERSIONS or list(sorted(versiondict.keys(), key=MSVCVersion, reverse=True))
# Override lazy detection by evaluating after the fact.
lazy_detect = getattr(Options.options, 'msvc_lazy', True)