From 2a1eeba691da5038f1a067600e3f01937af27339 Mon Sep 17 00:00:00 2001 From: Thomas Nagy Date: Sun, 22 May 2022 11:25:33 +0200 Subject: [PATCH] Sort visual studio versions by version number #2352 --- tests/msvc/wscript | 2 +- waflib/Tools/msvc.py | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/msvc/wscript b/tests/msvc/wscript index 58d08fe9..85f6e75d 100755 --- a/tests/msvc/wscript +++ b/tests/msvc/wscript @@ -9,7 +9,7 @@ def configure(ctx): 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'] + sorted_versions = ['msvc 16.6', 'msvc 16.0', 'msvc 15.9', 'msvc 15.0', 'msvc 14.0', 'msvc 12.0', 'msvc 11.0', 'msvc 9.0', 'winphone 8.0', 'wsdk 6.1'] def tt(msg, result, expected): color = 'RED' diff --git a/waflib/Tools/msvc.py b/waflib/Tools/msvc.py index e80e3314..92a79f36 100644 --- a/waflib/Tools/msvc.py +++ b/waflib/Tools/msvc.py @@ -103,15 +103,20 @@ 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: +class MSVCVersion(object): def __init__(self, ver): - x = ver.split() - self.a = x[0] - self.b = float(x[1]) + m = re.search('^(.*)\s+(\d+[.]\d+)', ver) + if m: + self.name = m.group(1) + self.number = float(m.group(2)) + else: + self.name = ver + self.number = 0. def __lt__(self, other): - if self.a == other.a: return self.b < other.b - return self.a < other.a + if self.number == other.number: + return self.name < other.name + return self.number < other.number @conf def setup_msvc(conf, versiondict): @@ -129,8 +134,6 @@ 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] desired_versions = getattr(Options.options, 'msvc_version', '').split(',') if desired_versions == ['']: - 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.