@@ -195,17 +195,24 @@ def fq_name(node):
195
195
return enums
196
196
197
197
198
- def write_json (messages , modules , extra_inputs : list [str ], filename : str , stable_ids ):
199
- str_catalog = dict (messages = list (messages .values ()), modules = list (modules .values ()))
198
+ def write_json (messages , modules , enums , extra_inputs : list [str ], filename : str , stable_ids ):
199
+ d = dict (messages = list (messages .values ()), modules = list (modules .values ()))
200
200
for msg in stable_ids .get ("messages" ):
201
- if not msg in str_catalog ["messages" ]:
202
- str_catalog ["messages" ].append (msg )
201
+ if not msg in d ["messages" ]:
202
+ d ["messages" ].append (msg )
203
203
for mod in stable_ids .get ("modules" ):
204
- if not mod in str_catalog ["modules" ]:
205
- str_catalog ["modules" ].append (mod )
204
+ if not mod in d ["modules" ]:
205
+ d ["modules" ].append (mod )
206
+
207
+ es = dict ()
208
+ for (k , (_ , v )) in enums .items ():
209
+ es .update ({k : {value : name for (name , value ) in v .items ()}})
210
+
211
+ str_catalog = dict (** d , enums = es )
206
212
for extra in extra_inputs :
207
213
with open (extra , "r" ) as f :
208
214
str_catalog .update (json .load (f ))
215
+
209
216
with open (filename , "w" ) as f :
210
217
json .dump (str_catalog , f , indent = 4 )
211
218
@@ -427,11 +434,8 @@ def main():
427
434
428
435
check_module_limit (modules , args .module_id_max )
429
436
430
- if args .json_output is not None :
431
- write_json (messages , modules , args .json_input , args .json_output , stable_output )
432
-
433
- if args .xml_output is not None :
434
- enums = {}
437
+ enums = {}
438
+ if args .xml_output is not None or args .json_output is not None :
435
439
if args .cpp_output is not None :
436
440
try :
437
441
enums = {
@@ -452,6 +456,10 @@ def main():
452
456
else :
453
457
print ("XML output without C++ output: enum lookup will not be available" )
454
458
459
+ if args .json_output is not None :
460
+ write_json (messages , modules , enums , args .json_input , args .json_output , stable_output )
461
+
462
+ if args .xml_output is not None :
455
463
write_xml (
456
464
messages ,
457
465
modules ,
0 commit comments