Apache Solr open-source search software
Handle adding back compat indexes for versions that are no longer supported
Steve Rowe0018003b7cc9
diff --git a/dev-tools/scripts/addBackcompatIndexes.py b/dev-tools/scripts/addBackcompatIndexes.pyindex 9e0963def5f..8a8b5b26d8a 100644--- a/dev-tools/scripts/addBackcompatIndexes.py+++ b/dev-tools/scripts/addBackcompatIndexes.py@@ -30,15 +30,16 @@ import urllib.requestimport reimport shutil-def create_and_add_index(source, indextype, version, temp_dir):+def create_and_add_index(source, indextype, index_version, current_version, temp_dir):if indextype in ('cfs', 'nocfs'):dirname = 'index.%s' % indextypeelse:dirname = indextype+ prefix = 'index' if current_version.is_back_compat_with(index_version) else 'unsupported'filename = {- 'cfs': 'index.%s-cfs.zip',- 'nocfs': 'index.%s-nocfs.zip'- }[indextype] % version+ 'cfs': '%s.%s-cfs.zip',+ 'nocfs': '%s.%s-nocfs.zip'+ }[indextype] % (prefix, index_version)print(' creating %s...' % filename, end='', flush=True)module = 'backward-codecs'index_dir = os.path.join('lucene', module, 'src/test/org/apache/lucene/index')@@ -84,11 +85,12 @@ def create_and_add_index(source, indextype, version, temp_dir):scriptutil.run('rm -rf %s' % bc_index_dir)print('done')-def update_backcompat_tests(types, version):+def update_backcompat_tests(types, index_version, current_version):print(' adding new indexes to backcompat tests...', end='', flush=True)module = 'lucene/backward-codecs'filename = '%s/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java' % module- matcher = re.compile(r'final static String\[\] oldNames = {|};')+ matcher = re.compile(r'final static String\[\] oldNames = {|};' if current_version.is_back_compat_with(index_version)+ else r'final String\[\] unsupportedNames = {|};')def find_version(x):x = x.strip()@@ -99,17 +101,17 @@ def update_backcompat_tests(types, version):start = Nonedef __call__(self, buffer, match, line):if self.start:- # find where we this version should exist+ # find where this version should existi = len(buffer) - 1v = find_version(buffer[i])- while i >= self.start and v.on_or_after(version):+ while i >= self.start and v.on_or_after(index_version):i -= 1v = find_version(buffer[i])i += 1 # readjust since we skipped past by 1# unfortunately python doesn't have a range remove from list...# here we want to remove any previous references to the version we are adding- while i < len(buffer) and version.on_or_after(find_version(buffer[i])):+ while i < len(buffer) and index_version.on_or_after(find_version(buffer[i])):buffer.pop(i)if i == len(buffer) and not buffer[-1].strip().endswith(","):@@ -119,7 +121,7 @@ def update_backcompat_tests(types, version):last = buffer[-1]spaces = ' ' * (len(last) - len(last.lstrip()))for (j, t) in enumerate(types):- newline = spaces + ('"%s-%s"' % (version, t))+ newline = spaces + ('"%s-%s"' % (index_version, t))if j < len(types) - 1 or i < len(buffer):newline += ','buffer.insert(i, newline + '\n')@@ -128,7 +130,7 @@ def update_backcompat_tests(types, version):buffer.append(line)return True- if 'oldNames' in line:+ if 'Names = {' in line:self.start = len(buffer) # location of first index namebuffer.append(line)return False@@ -213,11 +215,12 @@ def main():print('\nCreating backwards compatibility indexes')source = download_release(c.version, c.temp_dir, c.force)- create_and_add_index(source, 'cfs', c.version, c.temp_dir)- create_and_add_index(source, 'nocfs', c.version, c.temp_dir)+ current_version = scriptutil.Version.parse(scriptutil.find_current_version())+ create_and_add_index(source, 'cfs', c.version, current_version, c.temp_dir)+ create_and_add_index(source, 'nocfs', c.version, current_version, c.temp_dir)print('\nAdding backwards compatibility tests')- update_backcompat_tests(['cfs', 'nocfs'], c.version)+ update_backcompat_tests(['cfs', 'nocfs'], c.version, current_version)print('\nTesting changes')check_backcompat_tests()diff --git a/dev-tools/scripts/scriptutil.py b/dev-tools/scripts/scriptutil.pyindex bf7cec5dec4..9b264138349 100644--- a/dev-tools/scripts/scriptutil.py+++ b/dev-tools/scripts/scriptutil.py@@ -66,6 +66,11 @@ class Version(object):(self.bugfix > other.bugfix or self.bugfix == other.bugfix andself.prerelease >= other.prerelease)))+ def is_back_compat_with(self, other):+ if not self.on_or_after(other):+ raise Exception('Back compat check disallowed for newer version: %s < %s' % (self, other))+ return other.major + 1 >= self.major+def run(cmd):try:output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)