comparison contrib/packaging/hgpackaging/wix.py @ 44220:a70108a3d7cc stable

packaging: move the version normalization function to the util module This will be used with Inno as well. Since this module isn't platform specific, rename to include that this is meant for Windows. (Mac has a different format.) Differential Revision: https://phab.mercurial-scm.org/D8059
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 01 Feb 2020 00:32:46 -0500
parents 62111bc5ff87
children 481caa4a2244
comparison
equal deleted inserted replaced
44219:aab70b540d3d 44220:a70108a3d7cc
22 build_py2exe, 22 build_py2exe,
23 stage_install, 23 stage_install,
24 ) 24 )
25 from .util import ( 25 from .util import (
26 extract_zip_to_directory, 26 extract_zip_to_directory,
27 normalize_windows_version,
27 process_install_rules, 28 process_install_rules,
28 sign_with_signtool, 29 sign_with_signtool,
29 ) 30 )
30 31
31 32
67 with version_py.open('r', encoding='utf-8') as fh: 68 with version_py.open('r', encoding='utf-8') as fh:
68 source = fh.read().strip() 69 source = fh.read().strip()
69 70
70 m = re.search('version = b"(.*)"', source) 71 m = re.search('version = b"(.*)"', source)
71 return m.group(1) 72 return m.group(1)
72
73
74 def normalize_version(version):
75 """Normalize Mercurial version string so WiX accepts it.
76
77 Version strings have to be numeric ``A.B.C[.D]`` to conform with MSI's
78 requirements.
79
80 We normalize RC version or the commit count to a 4th version component.
81 We store this in the 4th component because ``A.B.C`` releases do occur
82 and we want an e.g. ``5.3rc0`` version to be semantically less than a
83 ``5.3.1rc2`` version. This requires always reserving the 3rd version
84 component for the point release and the ``X.YrcN`` release is always
85 point release 0.
86
87 In the case of an RC and presence of ``+`` suffix data, we can't use both
88 because the version format is limited to 4 components. We choose to use
89 RC and throw away the commit count in the suffix. This means we could
90 produce multiple installers with the same normalized version string.
91
92 >>> normalize_version("5.3")
93 '5.3.0'
94
95 >>> normalize_version("5.3rc0")
96 '5.3.0.0'
97
98 >>> normalize_version("5.3rc1")
99 '5.3.0.1'
100
101 >>> normalize_version("5.3rc1+2-abcdef")
102 '5.3.0.1'
103
104 >>> normalize_version("5.3+2-abcdef")
105 '5.3.0.2'
106 """
107 if '+' in version:
108 version, extra = version.split('+', 1)
109 else:
110 extra = None
111
112 # 4.9rc0
113 if version[:-1].endswith('rc'):
114 rc = int(version[-1:])
115 version = version[:-3]
116 else:
117 rc = None
118
119 # Ensure we have at least X.Y version components.
120 versions = [int(v) for v in version.split('.')]
121 while len(versions) < 3:
122 versions.append(0)
123
124 if len(versions) < 4:
125 if rc is not None:
126 versions.append(rc)
127 elif extra:
128 # <commit count>-<hash>+<date>
129 versions.append(int(extra.split('-')[0]))
130
131 return '.'.join('%d' % x for x in versions[0:4])
132 73
133 74
134 def ensure_vc90_merge_modules(build_dir): 75 def ensure_vc90_merge_modules(build_dir):
135 x86 = ( 76 x86 = (
136 download_entry( 77 download_entry(
410 extra_packages=EXTRA_PACKAGES, 351 extra_packages=EXTRA_PACKAGES,
411 extra_packages_script=extra_packages_script, 352 extra_packages_script=extra_packages_script,
412 ) 353 )
413 354
414 orig_version = version or find_version(source_dir) 355 orig_version = version or find_version(source_dir)
415 version = normalize_version(orig_version) 356 version = normalize_windows_version(orig_version)
416 print('using version string: %s' % version) 357 print('using version string: %s' % version)
417 if version != orig_version: 358 if version != orig_version:
418 print('(normalized from: %s)' % orig_version) 359 print('(normalized from: %s)' % orig_version)
419 360
420 if post_build_fn: 361 if post_build_fn: