summaryrefslogtreecommitdiffstats
path: root/scu_builders.py
diff options
context:
space:
mode:
authorRiteo <riteo@posteo.net>2024-03-13 17:54:14 +0100
committerRiteo <riteo@posteo.net>2024-03-15 15:43:53 +0100
commita5cf92664db9633b9fb1307a801d99de70d09aba (patch)
tree2b5a8cb9151897d807c0b6eef23e23005ba934e3 /scu_builders.py
parent89f70e98d209563abb4dbc1f8cd5d76c81eb7940 (diff)
downloadredot-engine-a5cf92664db9633b9fb1307a801d99de70d09aba.tar.gz
SCons: unify code generations routine and minimize timestamp changes
Previously, all of the code generation routines would just needlessly write the same files over and over, even when not needed. This became a problem with the advent of the experimental ninja backend for SCons, which can be trivially enabled with a few lines of code and relies on timestamp changes, making it thus impractical.
Diffstat (limited to 'scu_builders.py')
-rw-r--r--scu_builders.py53
1 files changed, 35 insertions, 18 deletions
diff --git a/scu_builders.py b/scu_builders.py
index 0435c0a4f5..b180cbc864 100644
--- a/scu_builders.py
+++ b/scu_builders.py
@@ -13,9 +13,9 @@ _scu_folders = set()
_max_includes_per_scu = 1024
-def clear_out_existing_files(output_folder, extension):
+def clear_out_stale_files(output_folder, extension, fresh_files):
output_folder = os.path.abspath(output_folder)
- # print("clear_out_existing_files from folder: " + output_folder)
+ # print("clear_out_stale_files from folder: " + output_folder)
if not os.path.isdir(output_folder):
# folder does not exist or has not been created yet,
@@ -23,8 +23,9 @@ def clear_out_existing_files(output_folder, extension):
return
for file in glob.glob(output_folder + "/*." + extension):
- # print("removed pre-existing file: " + file)
- os.remove(file)
+ if not file in fresh_files:
+ # print("removed stale file: " + file)
+ os.remove(file)
def folder_not_found(folder):
@@ -87,11 +88,16 @@ def write_output_file(file_count, include_list, start_line, end_line, output_fol
short_filename = output_filename_prefix + num_string + ".gen." + extension
output_filename = output_folder + "/" + short_filename
- if _verbose:
- print("SCU: Generating: %s" % short_filename)
-
output_path = Path(output_filename)
- output_path.write_text(file_text, encoding="utf8")
+
+ if not output_path.exists() or output_path.read_text() != file_text:
+ if _verbose:
+ print("SCU: Generating: %s" % short_filename)
+ output_path.write_text(file_text, encoding="utf8")
+ elif _verbose:
+ print("SCU: Generation not needed for: " + short_filename)
+
+ return output_filename
def write_exception_output_file(file_count, exception_string, output_folder, output_filename_prefix, extension):
@@ -109,11 +115,16 @@ def write_exception_output_file(file_count, exception_string, output_folder, out
short_filename = output_filename_prefix + "_exception" + num_string + ".gen." + extension
output_filename = output_folder + "/" + short_filename
- if _verbose:
- print("SCU: Generating: " + short_filename)
-
output_path = Path(output_filename)
- output_path.write_text(file_text, encoding="utf8")
+
+ if not output_path.exists() or output_path.read_text() != file_text:
+ if _verbose:
+ print("SCU: Generating: " + short_filename)
+ output_path.write_text(file_text, encoding="utf8")
+ elif _verbose:
+ print("SCU: Generation not needed for: " + short_filename)
+
+ return output_filename
def find_section_name(sub_folder):
@@ -214,10 +225,7 @@ def process_folder(folders, sought_exceptions=[], includes_per_scu=0, extension=
output_folder = abs_main_folder + "/scu/"
output_filename_prefix = "scu_" + out_filename
- # Clear out any existing files (usually we will be overwriting,
- # but we want to remove any that are pre-existing that will not be
- # overwritten, so as to not compile anything stale)
- clear_out_existing_files(output_folder, extension)
+ fresh_files = set()
for file_count in range(0, num_output_files):
end_line = start_line + lines_per_file
@@ -226,19 +234,28 @@ def process_folder(folders, sought_exceptions=[], includes_per_scu=0, extension=
if file_count == (num_output_files - 1):
end_line = len(found_includes)
- write_output_file(
+ fresh_file = write_output_file(
file_count, found_includes, start_line, end_line, output_folder, output_filename_prefix, extension
)
+ fresh_files.add(fresh_file)
+
start_line = end_line
# Write the exceptions each in their own scu gen file,
# so they can effectively compile in "old style / normal build".
for exception_count in range(len(found_exceptions)):
- write_exception_output_file(
+ fresh_file = write_exception_output_file(
exception_count, found_exceptions[exception_count], output_folder, output_filename_prefix, extension
)
+ fresh_files.add(fresh_file)
+
+ # Clear out any stale file (usually we will be overwriting if necessary,
+ # but we want to remove any that are pre-existing that will not be
+ # overwritten, so as to not compile anything stale).
+ clear_out_stale_files(output_folder, extension, fresh_files)
+
def generate_scu_files(max_includes_per_scu):
print("=============================")