@@ -199,8 +199,14 @@ def fq_name(node):
199199 return enums
200200
201201
202- def write_json (messages , modules , extra_inputs : list [str ], filename : str ):
202+ def write_json (messages , modules , extra_inputs : list [str ], filename : str , stable_ids ):
203203 str_catalog = dict (messages = list (messages .values ()), modules = list (modules .values ()))
204+ for msg in stable_ids .get ("messages" ):
205+ if not msg in str_catalog ["messages" ]:
206+ str_catalog ["messages" ].append (msg )
207+ for mod in stable_ids .get ("modules" ):
208+ if not mod in str_catalog ["modules" ]:
209+ str_catalog ["modules" ].append (mod )
204210 for extra in extra_inputs :
205211 with open (extra , "r" ) as f :
206212 str_catalog .update (json .load (f ))
@@ -213,10 +219,7 @@ def read_stable(stable_filenames: list[str]):
213219 for filename in stable_filenames :
214220 with open (filename , "r" ) as f :
215221 stable_catalog .update (json .load (f ))
216- return (
217- {stable_msg_key (msg ): msg ["id" ] for msg in stable_catalog ["messages" ]},
218- {m ["string" ]: m ["id" ] for m in stable_catalog ["modules" ]},
219- )
222+ return stable_catalog
220223
221224
222225def serialize_guids (client_node : et .Element , guid_id : str , guid_mask : str ):
@@ -371,6 +374,11 @@ def parse_cmdline():
371374 default = [],
372375 help = "Input filename(s) for previously generated JSON; this is used to fix stable IDs." ,
373376 )
377+ parser .add_argument (
378+ "--forget_old_ids" ,
379+ action = "store_true" ,
380+ help = "When on, stable IDs from a previous run are forgotten. By default, those strings are remembered in the output so that they will not be reused in future." ,
381+ )
374382 return parser .parse_args ()
375383
376384
@@ -388,17 +396,27 @@ def main():
388396 et ._escape_cdata = _escape_cdata
389397 args = parse_cmdline ()
390398
391- stable_ids = read_stable (args .stable_json )
399+ stable_catalog = read_stable (args .stable_json )
392400 try :
401+ stable_ids = (
402+ {stable_msg_key (msg ): msg ["id" ] for msg in stable_catalog ["messages" ]},
403+ {m ["string" ]: m ["id" ] for m in stable_catalog ["modules" ]},
404+ )
393405 modules , messages = read_input (args .input , stable_ids )
394406 except Exception as e :
395407 raise Exception (f"{ str (e )} from file { args .input } " )
396408
397409 if args .cpp_output is not None :
398410 write_cpp (messages , modules , args .cpp_headers , args .cpp_output )
399411
412+ stable_output = dict (messages = [], modules = [])
413+ if not args .forget_old_ids :
414+ stable_output = dict (
415+ messages = stable_catalog ["messages" ], modules = stable_catalog ["modules" ]
416+ )
417+
400418 if args .json_output is not None :
401- write_json (messages , modules , args .json_input , args .json_output )
419+ write_json (messages , modules , args .json_input , args .json_output , stable_output )
402420
403421 if args .xml_output is not None :
404422 enums = {}
0 commit comments