Commit a7657a05 authored by Daniel Bratell's avatar Daniel Bratell Committed by Commit Bot

Sort Win SDK versions by version sorting rules (reland)

This should have no practical effect on current data but version
numbers need to be sorted so that 1.12 is higher than 1.9 and
the current code didn't do that.

This is a reland of https://crrev.com/c/1605980 with a typo fixed.
The initial patch tried to sort |vc_component_msvc_root| (a string)
instead of the list |vc_component_msvc_contents|.

Change-Id: I961a4e0d11c9e626e2890682f6bf416c8e7e9d28
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1609831Reviewed-by: default avatarBruce Dawson <brucedawson@chromium.org>
Commit-Queue: Daniel Bratell <bratell@opera.com>
Cr-Commit-Position: refs/heads/master@{#662138}
parent f5e6711b
...@@ -229,6 +229,23 @@ def _CopyRuntimeImpl(target, source, verbose=True): ...@@ -229,6 +229,23 @@ def _CopyRuntimeImpl(target, source, verbose=True):
# keep it readable. # keep it readable.
os.chmod(target, stat.S_IWRITE | stat.S_IREAD) os.chmod(target, stat.S_IWRITE | stat.S_IREAD)
def _SortByHighestVersionNumberFirst(list_of_str_versions):
"""This sorts |list_of_str_versions| according to version number rules
so that version "1.12" is higher than version "1.9". Does not work
with non-numeric versions like 1.4.a8 which will be higher than
1.4.a12. It does handle the versions being embedded in file paths.
"""
def to_int_if_int(x):
try:
return int(x)
except ValueError:
return x
def to_number_sequence(x):
part_sequence = re.split(r'[\\/\.]', x)
return [to_int_if_int(x) for x in part_sequence]
list_of_str_versions.sort(key=to_number_sequence, reverse=True)
def _CopyUCRTRuntime(target_dir, source_dir, target_cpu, dll_pattern, suffix): def _CopyUCRTRuntime(target_dir, source_dir, target_cpu, dll_pattern, suffix):
"""Copy both the msvcp and vccorlib runtime DLLs, only if the target doesn't """Copy both the msvcp and vccorlib runtime DLLs, only if the target doesn't
...@@ -265,7 +282,7 @@ def _CopyUCRTRuntime(target_dir, source_dir, target_cpu, dll_pattern, suffix): ...@@ -265,7 +282,7 @@ def _CopyUCRTRuntime(target_dir, source_dir, target_cpu, dll_pattern, suffix):
redist_dir = os.path.join(win_sdk_dir, 'Redist') redist_dir = os.path.join(win_sdk_dir, 'Redist')
version_dirs = glob.glob(os.path.join(redist_dir, '10.*')) version_dirs = glob.glob(os.path.join(redist_dir, '10.*'))
if len(version_dirs) > 0: if len(version_dirs) > 0:
version_dirs.sort(reverse=True) _SortByHighestVersionNumberFirst(version_dirs)
redist_dir = version_dirs[0] redist_dir = version_dirs[0]
ucrt_dll_dirs = os.path.join(redist_dir, 'ucrt', 'DLLs', target_cpu) ucrt_dll_dirs = os.path.join(redist_dir, 'ucrt', 'DLLs', target_cpu)
ucrt_files = glob.glob(os.path.join(ucrt_dll_dirs, 'api-ms-win-*.dll')) ucrt_files = glob.glob(os.path.join(ucrt_dll_dirs, 'api-ms-win-*.dll'))
...@@ -282,7 +299,7 @@ def _CopyUCRTRuntime(target_dir, source_dir, target_cpu, dll_pattern, suffix): ...@@ -282,7 +299,7 @@ def _CopyUCRTRuntime(target_dir, source_dir, target_cpu, dll_pattern, suffix):
sdk_redist_root = os.path.join(win_sdk_dir, 'bin') sdk_redist_root = os.path.join(win_sdk_dir, 'bin')
sdk_bin_sub_dirs = os.listdir(sdk_redist_root) sdk_bin_sub_dirs = os.listdir(sdk_redist_root)
# Select the most recent SDK if there are multiple versions installed. # Select the most recent SDK if there are multiple versions installed.
sdk_bin_sub_dirs.sort(reverse=True) _SortByHighestVersionNumberFirst(sdk_bin_sub_dirs)
for directory in sdk_bin_sub_dirs: for directory in sdk_bin_sub_dirs:
sdk_redist_root_version = os.path.join(sdk_redist_root, directory) sdk_redist_root_version = os.path.join(sdk_redist_root, directory)
if not os.path.isdir(sdk_redist_root_version): if not os.path.isdir(sdk_redist_root_version):
...@@ -307,7 +324,7 @@ def FindVCComponentRoot(component): ...@@ -307,7 +324,7 @@ def FindVCComponentRoot(component):
'VC', component, 'MSVC') 'VC', component, 'MSVC')
vc_component_msvc_contents = os.listdir(vc_component_msvc_root) vc_component_msvc_contents = os.listdir(vc_component_msvc_root)
# Select the most recent toolchain if there are several. # Select the most recent toolchain if there are several.
vc_component_msvc_contents.sort(reverse=True) _SortByHighestVersionNumberFirst(vc_component_msvc_contents)
for directory in vc_component_msvc_contents: for directory in vc_component_msvc_contents:
if not os.path.isdir(os.path.join(vc_component_msvc_root, directory)): if not os.path.isdir(os.path.join(vc_component_msvc_root, directory)):
continue continue
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment