@@ -199,8 +199,14 @@ def fq_name(node):
199
199
return enums
200
200
201
201
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 ):
203
203
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 )
204
210
for extra in extra_inputs :
205
211
with open (extra , "r" ) as f :
206
212
str_catalog .update (json .load (f ))
@@ -213,10 +219,7 @@ def read_stable(stable_filenames: list[str]):
213
219
for filename in stable_filenames :
214
220
with open (filename , "r" ) as f :
215
221
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
220
223
221
224
222
225
def serialize_guids (client_node : et .Element , guid_id : str , guid_mask : str ):
@@ -371,6 +374,11 @@ def parse_cmdline():
371
374
default = [],
372
375
help = "Input filename(s) for previously generated JSON; this is used to fix stable IDs." ,
373
376
)
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
+ )
374
382
return parser .parse_args ()
375
383
376
384
@@ -388,17 +396,27 @@ def main():
388
396
et ._escape_cdata = _escape_cdata
389
397
args = parse_cmdline ()
390
398
391
- stable_ids = read_stable (args .stable_json )
399
+ stable_catalog = read_stable (args .stable_json )
392
400
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
+ )
393
405
modules , messages = read_input (args .input , stable_ids )
394
406
except Exception as e :
395
407
raise Exception (f"{ str (e )} from file { args .input } " )
396
408
397
409
if args .cpp_output is not None :
398
410
write_cpp (messages , modules , args .cpp_headers , args .cpp_output )
399
411
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
+
400
418
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 )
402
420
403
421
if args .xml_output is not None :
404
422
enums = {}
0 commit comments