Skip to content

Commit

Permalink
[CLI] Only generate files if contents change. (qmk#24038)
Browse files Browse the repository at this point in the history
Don't overwrite if the content doesn't change.
  • Loading branch information
tzarc authored Jul 24, 2024
1 parent 8c5acde commit 8c35011
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/python/qmk/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ def dump_lines(output_file, lines, quiet=True):
if output_file and output_file.name != '-':
output_file.parent.mkdir(parents=True, exist_ok=True)
if output_file.exists():
with open(output_file, 'r', encoding='utf-8', newline='\n') as f:
existing = f.read()
if existing == generated:
if not quiet:
cli.log.info(f'No changes to {output_file.name}.')
return
output_file.replace(output_file.parent / (output_file.name + '.bak'))
output_file.write_text(generated, encoding='utf-8')

Expand Down

0 comments on commit 8c35011

Please sign in to comment.