Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-64595: Argument Clinic: Touch source file if any output file changed
  • Loading branch information
erlend-aasland committed May 4, 2023
commit 6ca580c17a14b0ccab6ab9c1575bd9d49f3626fa
18 changes: 12 additions & 6 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1943,12 +1943,12 @@ def dump(self):
return_converters = {}


def write_file(filename, new_contents):
def write_file(filename, new_contents, force=False):
Comment thread
erlend-aasland marked this conversation as resolved.
try:
with open(filename, 'r', encoding="utf-8") as fp:
old_contents = fp.read()

if old_contents == new_contents:
if old_contents == new_contents and not force:
# no change: avoid modifying the file modification time
return
except FileNotFoundError:
Expand Down Expand Up @@ -2112,6 +2112,8 @@ def parse(self, input):
traceback.format_exc().rstrip())
printer.print_block(block)

clinic_out = []
Comment thread
erlend-aasland marked this conversation as resolved.

# these are destinations not buffers
for name, destination in self.destinations.items():
if destination.type == 'suppress':
Expand Down Expand Up @@ -2151,10 +2153,11 @@ def parse(self, input):
block.input = 'preserve\n'
printer_2 = BlockPrinter(self.language)
printer_2.print_block(block, core_includes=True)
write_file(destination.filename, printer_2.f.getvalue())
pair = destination.filename, printer_2.f.getvalue()
clinic_out.append(pair)
continue

return printer.f.getvalue()
return printer.f.getvalue(), clinic_out


def _module_and_class(self, fields):
Expand Down Expand Up @@ -2210,9 +2213,12 @@ def parse_file(filename, *, verify=True, output=None):
return

clinic = Clinic(language, verify=verify, filename=filename)
cooked = clinic.parse(raw)
src_out, clinic_out = clinic.parse(raw)

write_file(output, cooked)
force = bool(clinic_out)
write_file(output, src_out, force=force)
Comment thread
erlend-aasland marked this conversation as resolved.
for fn, data in clinic_out:
write_file(fn, data)


def compute_checksum(input, length=None):
Expand Down