dfhack/ci/check-rpc.py

118 lines
3.9 KiB
Python

2020-06-29 22:29:30 -06:00
#!/usr/bin/env python3
2018-07-04 12:22:04 -06:00
import glob
import itertools
2018-07-04 12:22:04 -06:00
import sys
actual = {'': {}}
2023-08-03 23:12:50 -06:00
SEP = ('=' * 80)
2018-07-04 12:22:04 -06:00
with open(sys.argv[1]) as f:
plugin_name = ''
for line in f:
line = line.rstrip()
if line.startswith('// Plugin: '):
plugin_name = line.split(' ')[2]
if plugin_name not in actual:
actual[plugin_name] = {}
elif line.startswith('// RPC '):
parts = line.split(' ')
actual[plugin_name][parts[2]] = (parts[4], parts[6])
expected = {'': {}}
for p in glob.iglob('library/proto/*.proto'):
with open(p) as f:
for line in f:
line = line.rstrip()
if line.startswith('// RPC '):
parts = line.split(' ')
expected[''][parts[2]] = (parts[4], parts[6])
for p in itertools.chain(glob.iglob('plugins/proto/*.proto'), glob.iglob('plugins/*/proto/*.proto')):
2018-07-04 12:22:04 -06:00
plugin_name = ''
with open(p) as f:
for line in f:
line = line.rstrip()
if line.startswith('// Plugin: '):
plugin_name = line.split(' ')[2]
if plugin_name not in expected:
expected[plugin_name] = {}
break
if plugin_name == '':
continue
with open(p) as f:
for line in f:
line = line.rstrip()
if line.startswith('// RPC '):
parts = line.split(' ')
expected[plugin_name][parts[2]] = (parts[4], parts[6])
error_count = 0
for plugin_name in actual:
methods = actual[plugin_name]
if plugin_name not in expected:
2023-08-03 23:12:50 -06:00
print(SEP)
2018-07-04 12:22:04 -06:00
print('Missing documentation for plugin proto files: ' + plugin_name)
print('Add the following lines:')
print('// Plugin: ' + plugin_name)
error_count += 1
for m in methods:
io = methods[m]
print('// RPC ' + m + ' : ' + io[0] + ' -> ' + io[1])
error_count += 1
else:
missing = []
wrong = []
for m in methods:
io = methods[m]
if m in expected[plugin_name]:
if expected[plugin_name][m] != io:
2018-12-28 22:15:45 -07:00
wrong.append('// RPC ' + m + ' : ' + io[0] + ' -> ' + io[1])
2018-07-04 12:22:04 -06:00
else:
2018-12-28 22:15:45 -07:00
missing.append('// RPC ' + m + ' : ' + io[0] + ' -> ' + io[1])
2018-07-04 12:22:04 -06:00
if len(missing) > 0:
2023-08-03 23:12:50 -06:00
print(SEP)
2018-07-04 12:22:04 -06:00
print('Incomplete documentation for ' + ('core' if plugin_name == '' else 'plugin "' + plugin_name + '"') + ' proto files. Add the following lines:')
for m in missing:
print(m)
error_count += 1
if len(wrong) > 0:
2023-08-03 23:12:50 -06:00
print(SEP)
2018-07-04 12:22:04 -06:00
print('Incorrect documentation for ' + ('core' if plugin_name == '' else 'plugin "' + plugin_name + '"') + ' proto files. Replace the following comments:')
for m in wrong:
print(m)
error_count += 1
for plugin_name in expected:
methods = expected[plugin_name]
if plugin_name not in actual:
2023-08-03 23:12:50 -06:00
print(SEP)
2018-07-04 12:22:04 -06:00
print('Incorrect documentation for plugin proto files: ' + plugin_name)
print('The following methods are documented, but the plugin does not provide any RPC methods:')
for m in methods:
io = methods[m]
print('// RPC ' + m + ' : ' + io[0] + ' -> ' + io[1])
error_count += 1
else:
missing = []
for m in methods:
io = methods[m]
if m not in actual[plugin_name]:
2018-12-28 22:15:45 -07:00
missing.append('// RPC ' + m + ' : ' + io[0] + ' -> ' + io[1])
2018-07-04 12:22:04 -06:00
if len(missing) > 0:
2023-08-03 23:12:50 -06:00
print(SEP)
2018-07-04 12:22:04 -06:00
print('Incorrect documentation for ' + ('core' if plugin_name == '' else 'plugin "' + plugin_name + '"') + ' proto files. Remove the following lines:')
for m in missing:
print(m)
error_count += 1
sys.exit(min(100, error_count))