mirror of
https://github.com/Keychron/qmk_firmware.git
synced 2024-11-25 01:47:10 +06:00
[CLI] Only generate files if contents change. (#24038)
Don't overwrite if the content doesn't change.
This commit is contained in:
parent
8c5acdea12
commit
8c35011d0a
|
@ -101,6 +101,12 @@ def dump_lines(output_file, lines, quiet=True):
|
||||||
if output_file and output_file.name != '-':
|
if output_file and output_file.name != '-':
|
||||||
output_file.parent.mkdir(parents=True, exist_ok=True)
|
output_file.parent.mkdir(parents=True, exist_ok=True)
|
||||||
if output_file.exists():
|
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.replace(output_file.parent / (output_file.name + '.bak'))
|
||||||
output_file.write_text(generated, encoding='utf-8')
|
output_file.write_text(generated, encoding='utf-8')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user