Skip to content

Commit

Permalink
Remove out-of-date Loom logic and refine range check in JavaCompliance.
Browse files Browse the repository at this point in the history
  • Loading branch information
oraluben committed Jun 27, 2022
1 parent c900245 commit 6663c03
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
9 changes: 0 additions & 9 deletions mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -13490,7 +13490,6 @@ def __init__(self, versionString):
while i > 0 and self.parts[i - 1] == 0:
i -= 1
self.strippedParts = tuple(list(self.parts)[:i])
self._loom = False

def __str__(self):
return self.versionString
Expand Down Expand Up @@ -13614,10 +13613,6 @@ def _checkOutput(out):

self._is_openjdk = 'openjdk' in output.lower()

# Once Loom is merged into the JDK, the JDK version
# number will be used to determine if the JDK includes Loom.
self._is_loom = 'loom' in output.lower()

# hotspot can print a warning, e.g. if there's a .hotspot_compiler file in the cwd
output = output.split('\n')
version = None
Expand All @@ -13640,10 +13635,6 @@ def _checkOutput0(out):
ver = self.version.parts[1] if self.version.parts[0] == 1 else self.version.parts[0]
self.javaCompliance = JavaCompliance(ver)

if self._is_loom:
self.javaCompliance._loom = True
self.version._loom = True

self.debug_args = java_debug_args()

def is_openjdk_based(self):
Expand Down
59 changes: 37 additions & 22 deletions mx_javacompliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ class JavaCompliance(mx.Comparable):
# Examples: "1.8", "13"
_singleton_range_re = re.compile(r'(1\.)?(\d+)$')

# Examples: "17-loom"
_loom_re = re.compile(r'(\d+)-loom$')

@staticmethod
def _error_prefix(spec, part_index, part):
return 'JavaCompliance("{}"): Part {} ("{}")'.format(spec, part_index, part)
Expand Down Expand Up @@ -104,6 +101,15 @@ def __contains__(self, other):
if self._high is None:
return True
return value <= self._high
elif isinstance(other, JavaCompliance._Range):
if other._high is None:
# open range is considered not match, e.g. '1.8+' not in '1.8..11'
return False
if other._low < self._low:
return False
if self._high is None:
return True
return other._high <= self._high
return False

def _values(self, stop=None):
Expand Down Expand Up @@ -172,10 +178,6 @@ def _check_part_value(prefix, value, value_desc):
if m:
low = _check_part_value(m.group(1), m.group(2), 'bound')
return JavaCompliance._Range(low, None)
m = JavaCompliance._loom_re.match(part)
if m:
self._loom = True
part = m.group(1)
m = JavaCompliance._singleton_range_re.match(part)
if m:
low = _check_part_value(m.group(1), m.group(2), 'bound')
Expand Down Expand Up @@ -215,29 +217,16 @@ def __cmp__(self, other):
def __contains__(self, other):
if isinstance(other, (int, str)):
other = JavaCompliance(other)
assert other._high_bound() is not None, "Contains check cannot be done with version ranges"
r = mx.compare(self.value, other.value)
if r == 0:
return True
elif r > 0:
return False
else: # r < 0
if self._high_bound() is None:
return True
else:
return mx.compare(self._high_bound(), other.value) >= 0
return all(any((other_part in self_part) for self_part in self._parts) for other_part in other._parts)

def __hash__(self):
return hash((self._parts, self._loom))
return hash(self._parts)

def _is_exact_bound(self):
return self.value == self._high_bound()

def _exact_match(self, version):
assert isinstance(version, mx.VersionSpec)
if self._loom and not version._loom:
# only skip those suites who require Loom
return False
if len(version.parts) > 0:
if len(version.parts) > 1 and version.parts[0] == 1:
# First part is a '1', e.g. '1.8.0'.
Expand Down Expand Up @@ -283,6 +272,8 @@ def _test():
Mx suite specific tests.
"""

from collections import namedtuple

# JavaCompliance tests
good_specs = [
(2, True),
Expand Down Expand Up @@ -317,6 +308,27 @@ def _test():
'4,7,1..3,',
'4..5,1..3',
]
range_case = namedtuple('range_case', ['spec', 'range_spec', 'should_match'])
range_specs = [
range_case('1.8', '1.8', True),
range_case('11', '11', True),
range_case('17', '17', True),
range_case('1.8', '1.7', False),
range_case('1.8', '11', False),
range_case('17', '1.8', False),
range_case('1.8', '11..17', False),
range_case('11', '11..17', True),
range_case('15', '11..17', True),
range_case('17', '11..17', True),
range_case('19', '11..17', False),
range_case('11..17', '11..17', True),
range_case('13..14', '11..17', True),
range_case('11..19', '11..17', False),
range_case('16', '11..15,17', False),
range_case('11..12,14..15', '11..15,17', True),
range_case('11,12,13,14,15,16,17', '11..17', True),
range_case('11+', '11..17', False),
]
for spec, exact in good_specs:
p = mx.JavaCompliance(spec)
assert p._is_exact_bound() is exact, p
Expand All @@ -342,3 +354,6 @@ def _parse_error(msg):
mx.abort('expected SpecError while parsing "{}"'.format(spec))
except SpecError:
pass
for spec, range_spec, should_match in range_specs:
match = spec in mx.JavaCompliance(range_spec)
assert match == should_match, '"{}" in "{}" should returns {}'.format(spec, range_spec, should_match)
2 changes: 1 addition & 1 deletion mx_javamodules.py
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ def parse_requiresConcealed_attribute(jdk, value, result, importer, context, mod
if '@' in module:
module, java_compliance = module.split('@', 1)
java_compliance = mx_javacompliance.JavaCompliance(java_compliance, context=context)
if java_compliance not in jdk.javaCompliance:
if jdk.javaCompliance not in java_compliance:
continue

matches = [jmd for jmd in all_modules if jmd.name == module]
Expand Down

0 comments on commit 6663c03

Please sign in to comment.