##// END OF EJS Templates
packaging: move the version normalization function to the util module...
Matt Harbison -
r44707:a70108a3 stable
parent child Browse files
Show More
@@ -82,6 +82,66 b' def windows_10_sdk_info():'
82 }
82 }
83
83
84
84
85 def normalize_windows_version(version):
86 """Normalize Mercurial version string so WiX/Inno accepts it.
87
88 Version strings have to be numeric ``A.B.C[.D]`` to conform with MSI's
89 requirements.
90
91 We normalize RC version or the commit count to a 4th version component.
92 We store this in the 4th component because ``A.B.C`` releases do occur
93 and we want an e.g. ``5.3rc0`` version to be semantically less than a
94 ``5.3.1rc2`` version. This requires always reserving the 3rd version
95 component for the point release and the ``X.YrcN`` release is always
96 point release 0.
97
98 In the case of an RC and presence of ``+`` suffix data, we can't use both
99 because the version format is limited to 4 components. We choose to use
100 RC and throw away the commit count in the suffix. This means we could
101 produce multiple installers with the same normalized version string.
102
103 >>> normalize_windows_version("5.3")
104 '5.3.0'
105
106 >>> normalize_windows_version("5.3rc0")
107 '5.3.0.0'
108
109 >>> normalize_windows_version("5.3rc1")
110 '5.3.0.1'
111
112 >>> normalize_windows_version("5.3rc1+2-abcdef")
113 '5.3.0.1'
114
115 >>> normalize_windows_version("5.3+2-abcdef")
116 '5.3.0.2'
117 """
118 if '+' in version:
119 version, extra = version.split('+', 1)
120 else:
121 extra = None
122
123 # 4.9rc0
124 if version[:-1].endswith('rc'):
125 rc = int(version[-1:])
126 version = version[:-3]
127 else:
128 rc = None
129
130 # Ensure we have at least X.Y version components.
131 versions = [int(v) for v in version.split('.')]
132 while len(versions) < 3:
133 versions.append(0)
134
135 if len(versions) < 4:
136 if rc is not None:
137 versions.append(rc)
138 elif extra:
139 # <commit count>-<hash>+<date>
140 versions.append(int(extra.split('-')[0]))
141
142 return '.'.join('%d' % x for x in versions[0:4])
143
144
85 def find_signtool():
145 def find_signtool():
86 """Find signtool.exe from the Windows SDK."""
146 """Find signtool.exe from the Windows SDK."""
87 sdk = windows_10_sdk_info()
147 sdk = windows_10_sdk_info()
@@ -24,6 +24,7 b' from .py2exe import ('
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 )
@@ -71,66 +72,6 b' def find_version(source_dir: pathlib.Pat'
71 return m.group(1)
72 return m.group(1)
72
73
73
74
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
133
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(
@@ -412,7 +353,7 b' def build_installer('
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)
General Comments 0
You need to be logged in to leave comments. Login now