Skip to content

Commit c971ae9

Browse files
allevatoswiple-rules-gardener
authored andcommitted
Work around a bug in DottedVersion.compare_to.
It appears that the comparator erroneously reports that `10.0.0.10A255 >= 10.2.0.10E125`; the problem is in the handling of the last component. To avoid this, we trim the version number down to at most three components until the bug is fixed. RELNOTES: None. PiperOrigin-RevId: 244975722
1 parent 965c373 commit c971ae9

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

swift/internal/xcode_swift_toolchain.bzl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,20 @@ def _is_macos(platform):
184184
"""
185185
return platform.platform_type == apple_common.platform_type.macos
186186

187+
def _trim_version(version):
188+
"""Trim the given version number down to a maximum of three components.
189+
190+
Args:
191+
version: The version number to trim; either a string or a `DottedVersion` value.
192+
193+
Returns:
194+
The trimmed version number as a `DottedVersion` value.
195+
"""
196+
version = str(version)
197+
parts = version.split(".")
198+
maxparts = min(len(parts), 3)
199+
return apple_common.dotted_version(".".join(parts[:maxparts]))
200+
187201
def _is_xcode_at_least_version(xcode_config, desired_version):
188202
"""Returns True if we are building with at least the given Xcode version.
189203
@@ -200,8 +214,10 @@ def _is_xcode_at_least_version(xcode_config, desired_version):
200214
fail("Could not determine Xcode version at all. This likely means Xcode isn't " +
201215
"available; if you think this is a mistake, please file an issue.")
202216

203-
desired_version_value = apple_common.dotted_version(desired_version)
204-
return current_version >= desired_version_value
217+
# TODO(b/131195460): DottedVersion comparison is broken for four-component versions that are
218+
# returned by modern Xcodes. Work around it for now.
219+
desired_version_value = _trim_version(desired_version)
220+
return _trim_version(current_version) >= desired_version_value
205221

206222
def _modified_action_args(
207223
action_args,

0 commit comments

Comments
 (0)