@@ -1954,12 +1954,12 @@ def dump(self):
19541954return_converters = {}
19551955
19561956
1957- def write_file (filename , new_contents ):
1957+ def write_file (filename , new_contents , force = False ):
19581958 try :
19591959 with open (filename , 'r' , encoding = "utf-8" ) as fp :
19601960 old_contents = fp .read ()
19611961
1962- if old_contents == new_contents :
1962+ if old_contents == new_contents and not force :
19631963 # no change: avoid modifying the file modification time
19641964 return
19651965 except FileNotFoundError :
@@ -2123,6 +2123,8 @@ def parse(self, input):
21232123 traceback .format_exc ().rstrip ())
21242124 printer .print_block (block )
21252125
2126+ clinic_out = []
2127+
21262128 # these are destinations not buffers
21272129 for name , destination in self .destinations .items ():
21282130 if destination .type == 'suppress' :
@@ -2162,10 +2164,11 @@ def parse(self, input):
21622164 block .input = 'preserve\n '
21632165 printer_2 = BlockPrinter (self .language )
21642166 printer_2 .print_block (block , core_includes = True )
2165- write_file (destination .filename , printer_2 .f .getvalue ())
2167+ pair = destination .filename , printer_2 .f .getvalue ()
2168+ clinic_out .append (pair )
21662169 continue
21672170
2168- return printer .f .getvalue ()
2171+ return printer .f .getvalue (), clinic_out
21692172
21702173
21712174 def _module_and_class (self , fields ):
@@ -2221,9 +2224,13 @@ def parse_file(filename, *, verify=True, output=None):
22212224 return
22222225
22232226 clinic = Clinic (language , verify = verify , filename = filename )
2224- cooked = clinic .parse (raw )
2227+ src_out , clinic_out = clinic .parse (raw )
22252228
2226- write_file (output , cooked )
2229+ # If clinic output changed, force updating the source file as well.
2230+ force = bool (clinic_out )
2231+ write_file (output , src_out , force = force )
2232+ for fn , data in clinic_out :
2233+ write_file (fn , data )
22272234
22282235
22292236def compute_checksum (input , length = None ):
0 commit comments