From 406c8b79fe767b48da5a2d420eb5227db7cee899 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 4 Jan 2023 10:40:30 -0800
Subject: [PATCH] rename_symbols: only write new file if contents have changed
Also don't stop for other exceptions, just print them and keep going
---
build-scripts/rename_symbols.py | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/build-scripts/rename_symbols.py b/build-scripts/rename_symbols.py
index 2c53d224bc75..ab65c60a1ea8 100755
--- a/build-scripts/rename_symbols.py
+++ b/build-scripts/rename_symbols.py
@@ -78,11 +78,15 @@ def create_substring_regex_from_replacements(replacements):
def replace_symbols_in_file(file, regex, replacements):
try:
with file.open("r", encoding="UTF-8", newline="") as rfp:
- contents = regex.sub(lambda mo: replacements[mo.string[mo.start():mo.end()]], rfp.read())
- with file.open("w", encoding="UTF-8", newline="") as wfp:
- wfp.write(contents)
+ original = rfp.read()
+ contents = regex.sub(lambda mo: replacements[mo.string[mo.start():mo.end()]], original)
+ if contents != original:
+ with file.open("w", encoding="UTF-8", newline="") as wfp:
+ wfp.write(contents)
except UnicodeDecodeError:
print("%s is not text, skipping" % file)
+ except Exception as err:
+ print("%s" % err)
def replace_symbols_in_dir(path, regex, replacements):