Path: blob/main/tools/maint/check_struct_info.py
4150 views
#!/usr/bin/env python312"""Find entries in struct_info.json that are not needd by3any JS library code and can be removed."""45import json6import os7import sys8import subprocess910script_dir = os.path.dirname(os.path.abspath(__file__))11root_dir = os.path.dirname(os.path.dirname(script_dir))1213sys.path.insert(0, root_dir)1415from tools import utils161718def check_structs(info):19for struct, values in info['structs'].items():20key = 'C_STRUCTS\\.' + struct + '\\.'21# grep --quiet ruturns 0 when there is a match22if subprocess.run(['git', 'grep', '--quiet', key], check=False).returncode != 0:23print(key)24else:25for value in values:26if value != '__size__':27key = 'C_STRUCTS\\.' + struct + '\\.' + value28# grep --quiet ruturns 0 when there is a match29if subprocess.run(['git', 'grep', '--quiet', key], check=False).returncode != 0:30print(key)313233def check_defines(info):34for define in info['defines']:35key = r'cDefs\.' + define + r'\>'36# grep --quiet ruturns 0 when there is a match37if subprocess.run(['git', 'grep', '--quiet', key], check=False).returncode != 0:38print(define)394041def main():42json_file = utils.path_from_root('src/struct_info_generated.json')43info = json.loads(utils.read_file(json_file))44check_structs(info)45check_defines(info)46return 0474849if __name__ == '__main__':50sys.exit(main())515253