@@ -195,17 +195,24 @@ def fq_name(node):
195195 return enums
196196
197197
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 ()))
200200 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 )
203203 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 )
206212 for extra in extra_inputs :
207213 with open (extra , "r" ) as f :
208214 str_catalog .update (json .load (f ))
215+
209216 with open (filename , "w" ) as f :
210217 json .dump (str_catalog , f , indent = 4 )
211218
@@ -427,11 +434,8 @@ def main():
427434
428435 check_module_limit (modules , args .module_id_max )
429436
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 :
435439 if args .cpp_output is not None :
436440 try :
437441 enums = {
@@ -452,6 +456,10 @@ def main():
452456 else :
453457 print ("XML output without C++ output: enum lookup will not be available" )
454458
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 :
455463 write_xml (
456464 messages ,
457465 modules ,
0 commit comments