mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-18 14:34:52 +02:00
Fix spurious rebuilds of generated go code
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from contextlib import contextmanager, suppress
|
||||
from functools import lru_cache
|
||||
@@ -295,7 +296,7 @@ var DocTitleMap = map[string]string{serialize_go_dict(ref_map['doc'])}
|
||||
# Boilerplate {{{
|
||||
|
||||
@contextmanager
|
||||
def replace_if_needed(path: str) -> Iterator[io.StringIO]:
|
||||
def replace_if_needed(path: str, show_diff: bool = False) -> Iterator[io.StringIO]:
|
||||
buf = io.StringIO()
|
||||
yield buf
|
||||
orig = ''
|
||||
@@ -305,6 +306,11 @@ def replace_if_needed(path: str) -> Iterator[io.StringIO]:
|
||||
new = f'// Code generated by {os.path.basename(__file__)}; DO NOT EDIT.\n\n' + new
|
||||
if orig != new:
|
||||
changed.append(path)
|
||||
if show_diff:
|
||||
with open(path + '.new', 'w') as f:
|
||||
f.write(new)
|
||||
subprocess.run(['diff', '-Naurp', path, f.name], stdout=open('/dev/tty', 'w'))
|
||||
os.remove(f.name)
|
||||
with open(path, 'w') as f:
|
||||
f.write(new)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user