|
38 | 38 |
|
39 | 39 |
|
40 | 40 |
|
41 |
| -def ValidateAttrs(config_attrs): |
| 41 | +def ValidateAttrs(config_attrs, file_path, linenum): |
42 | 42 | _type = config_attrs.get('type', 'int')
|
43 | 43 |
|
44 | 44 | # Validate attrs
|
@@ -192,26 +192,31 @@ def ValidateAttrs(config_attrs):
|
192 | 192 | if val in all_defines:
|
193 | 193 | resolved_defines[d] = all_defines[val]
|
194 | 194 |
|
195 |
| -for config_name in all_configs: |
| 195 | +for config_name, config_obj in all_configs.items(): |
| 196 | + file_path = os.path.join(scandir, config_obj['filename']) |
| 197 | + linenum = config_obj['line_number'] |
196 | 198 |
|
197 |
| - ValidateAttrs(all_configs[config_name]['attrs']) |
| 199 | + ValidateAttrs(config_obj['attrs'], file_path, linenum) |
198 | 200 |
|
199 | 201 | # Check that default values match up
|
200 |
| - if 'default' in all_configs[config_name]['attrs']: |
| 202 | + if 'default' in config_obj['attrs']: |
| 203 | + config_default = config_obj['attrs']['default'] |
201 | 204 | if config_name in all_defines:
|
202 |
| - if all_configs[config_name]['attrs']['default'] not in all_defines[config_name] and (config_name not in resolved_defines or all_configs[config_name]['attrs']['default'] not in resolved_defines[config_name]): |
203 |
| - if '/' in all_configs[config_name]['attrs']['default'] or ' ' in all_configs[config_name]['attrs']['default']: |
| 205 | + defines_obj = all_defines[config_name] |
| 206 | + if config_default not in defines_obj and (config_name not in resolved_defines or config_default not in resolved_defines[config_name]): |
| 207 | + if '/' in config_default or ' ' in config_default: |
204 | 208 | continue
|
205 | 209 | # There _may_ be multiple matching defines, but arbitrarily display just one in the error message
|
206 |
| - first_define_value = list(all_defines[config_name].keys())[0] |
207 |
| - raise Exception('Found {} at {}:{} with a default of {}, but #define says {} (at {}:{})'.format(config_name, os.path.join(scandir, all_configs[config_name]['filename']), all_configs[config_name]['line_number'], all_configs[config_name]['attrs']['default'], first_define_value, all_defines[config_name][first_define_value][0], all_defines[config_name][first_define_value][1])) |
| 210 | + first_define_value = list(defines_obj.keys())[0] |
| 211 | + first_define_file_path, first_define_linenum = defines_obj[first_define_value] |
| 212 | + raise Exception('Found {} at {}:{} with a default of {}, but #define says {} (at {}:{})'.format(config_name, file_path, linenum, config_default, first_define_value, first_define_file_path, first_define_linenum)) |
208 | 213 | else:
|
209 |
| - raise Exception('Found {} at {}:{} with a default of {}, but no matching #define found'.format(config_name, os.path.join(scandir, all_configs[config_name]['filename']), all_configs[config_name]['line_number'], all_configs[config_name]['attrs']['default'])) |
| 214 | + raise Exception('Found {} at {}:{} with a default of {}, but no matching #define found'.format(config_name, file_path, linenum, config_default)) |
210 | 215 |
|
211 | 216 | with open(outfile, 'w', newline='') as csvfile:
|
212 | 217 | fieldnames = ('name', 'location', 'description', 'type') + tuple(sorted(all_attrs - set(['type'])))
|
213 | 218 | writer = csv.DictWriter(csvfile, fieldnames=fieldnames, extrasaction='ignore', dialect='excel-tab')
|
214 | 219 |
|
215 | 220 | writer.writeheader()
|
216 |
| - for config_name in sorted(all_configs): |
217 |
| - writer.writerow({'name': config_name, 'location': '{}:{}'.format(all_configs[config_name]['filename'], all_configs[config_name]['line_number']), 'description': all_configs[config_name]['description'], **all_configs[config_name]['attrs']}) |
| 221 | + for config_name, config_obj in sorted(all_configs.items()): |
| 222 | + writer.writerow({'name': config_name, 'location': '{}:{}'.format(config_obj['filename'], config_obj['line_number']), 'description': config_obj['description'], **config_obj['attrs']}) |
0 commit comments