Skip to content

Commit 73278bf

Browse files
committed
SCons: Properly NoCache all text files
1 parent d33da79 commit 73278bf

File tree

10 files changed

+166
-249
lines changed

10 files changed

+166
-249
lines changed

SConstruct

+3
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,9 @@ env.Append(BUILDERS=GLSL_BUILDERS)
10391039
if env["compiledb"]:
10401040
env.Tool("compilation_db")
10411041
env.Alias("compiledb", env.CompilationDatabase())
1042+
env.NoCache(env.CompilationDatabase())
1043+
if not env["verbose"]:
1044+
env["COMPILATIONDB_COMSTR"] = "$GENCOMSTR"
10421045

10431046
if env["ninja"]:
10441047
if env.scons_version < (4, 2, 0):

editor/icons/SCsub

+7-9
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@ import os
77

88
import editor_icons_builders
99

10-
env["BUILDERS"]["MakeEditorIconsBuilder"] = Builder(
11-
action=env.Run(editor_icons_builders.make_editor_icons_action),
12-
suffix=".h",
13-
src_suffix=".svg",
14-
)
15-
1610
# Editor's own icons
1711
icon_sources = Glob("*.svg")
1812

1913
# Module icons
2014
for path in env.module_icons_paths:
2115
if not os.path.isabs(path):
22-
icon_sources += Glob("#" + path + "/*.svg") # Built-in.
16+
icon_sources += Glob(f"#{path}/*.svg") # Built-in.
2317
else:
24-
icon_sources += Glob(path + "/*.svg") # Custom.
18+
icon_sources += Glob(f"{path}/*.svg") # Custom.
2519

26-
env.Alias("editor_icons", [env.MakeEditorIconsBuilder("#editor/themes/editor_icons.gen.h", icon_sources)])
20+
env.CommandNoCache(
21+
"#editor/themes/editor_icons.gen.h",
22+
icon_sources,
23+
env.Run(editor_icons_builders.make_editor_icons_action),
24+
)

gles3_builders.py

+1
Original file line numberDiff line numberDiff line change
@@ -585,5 +585,6 @@ def build_gles3_header(
585585

586586

587587
def build_gles3_headers(target, source, env):
588+
env.NoCache(target)
588589
for x in source:
589590
build_gles3_header(str(x), include="drivers/gles3/shader_gles3.h", class_suffix="GLES3")

glsl_builders.py

+2
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class {out_file_class} : public ShaderRD {{
148148

149149

150150
def build_rd_headers(target, source, env):
151+
env.NoCache(target)
151152
for x in source:
152153
build_rd_header(filename=str(x))
153154

@@ -205,5 +206,6 @@ def build_raw_header(
205206

206207

207208
def build_raw_headers(target, source, env):
209+
env.NoCache(target)
208210
for x in source:
209211
build_raw_header(filename=str(x))

methods.py

+23-48
Original file line numberDiff line numberDiff line change
@@ -816,64 +816,39 @@ def get_size(start_path: str = ".") -> int:
816816
return total_size
817817

818818

819-
def clean_cache(cache_path: str, cache_limit: int, verbose: bool):
819+
def clean_cache(cache_path: str, cache_limit: int, verbose: bool) -> None:
820+
if not cache_limit:
821+
return
822+
820823
files = glob.glob(os.path.join(cache_path, "*", "*"))
821824
if not files:
822825
return
823826

824-
# Remove all text files, store binary files in list of (filename, size, atime).
825-
purge = []
826-
texts = []
827+
# Store files in list of (filename, size, atime).
827828
stats = []
828829
for file in files:
829830
try:
830-
# Save file stats to rewrite after modifying.
831-
tmp_stat = os.stat(file)
832-
# Failing a utf-8 decode is the easiest way to determine if a file is binary.
833-
try:
834-
with open(file, encoding="utf-8") as out:
835-
out.read(1024)
836-
except UnicodeDecodeError:
837-
stats.append((file, *tmp_stat[6:8]))
838-
# Restore file stats after reading.
839-
os.utime(file, (tmp_stat[7], tmp_stat[8]))
840-
else:
841-
texts.append(file)
831+
stats.append((file, *os.stat(file)[6:8]))
842832
except OSError:
843833
print_error(f'Failed to access cache file "{file}"; skipping.')
844834

845-
if texts:
846-
count = len(texts)
847-
for file in texts:
848-
try:
849-
os.remove(file)
850-
except OSError:
851-
print_error(f'Failed to remove cache file "{file}"; skipping.')
852-
count -= 1
853-
if verbose:
854-
print("Purging %d text %s from cache..." % (count, "files" if count > 1 else "file"))
855-
856-
if cache_limit:
857-
# Sort by most recent access (most sensible to keep) first. Search for the first entry where
858-
# the cache limit is reached.
859-
stats.sort(key=lambda x: x[2], reverse=True)
860-
sum = 0
861-
for index, stat in enumerate(stats):
862-
sum += stat[1]
863-
if sum > cache_limit:
864-
purge.extend([x[0] for x in stats[index:]])
865-
break
866-
867-
if purge:
868-
count = len(purge)
869-
for file in purge:
870-
try:
871-
os.remove(file)
872-
except OSError:
873-
print_error(f'Failed to remove cache file "{file}"; skipping.')
874-
count -= 1
875-
if verbose:
876-
print("Purging %d %s from cache..." % (count, "files" if count > 1 else "file"))
835+
# Sort by most recent access (most sensible to keep) first. Search for the first entry where
836+
# the cache limit is reached.
837+
stats.sort(key=lambda x: x[2], reverse=True)
838+
sum = 0
839+
for index, stat in enumerate(stats):
840+
sum += stat[1]
841+
if sum > cache_limit:
842+
purge = [x[0] for x in stats[index:]]
843+
count = len(purge)
844+
for file in purge:
845+
try:
846+
os.remove(file)
847+
except OSError:
848+
print_error(f'Failed to remove cache file "{file}"; skipping.')
849+
count -= 1
850+
if verbose:
851+
print_info(f"Purged {count} file{'s' if count else ''} from cache.")
877852

878853

879854
def prepare_cache(env) -> None:

modules/gdscript/editor/script_templates/SCsub

+1-10
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,4 @@ Import("env")
55

66
import editor.template_builders as build_template_gd
77

8-
env["BUILDERS"]["MakeGDTemplateBuilder"] = Builder(
9-
action=env.Run(build_template_gd.make_templates),
10-
suffix=".h",
11-
src_suffix=".gd",
12-
)
13-
14-
# Template files
15-
templates_sources = Glob("*/*.gd")
16-
17-
env.Alias("editor_template_gd", [env.MakeGDTemplateBuilder("templates.gen.h", templates_sources)])
8+
env.CommandNoCache("templates.gen.h", Glob("*/*.gd"), env.Run(build_template_gd.make_templates))

modules/mono/editor/script_templates/SCsub

+1-10
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,4 @@ Import("env")
55

66
import editor.template_builders as build_template_cs
77

8-
env["BUILDERS"]["MakeCSharpTemplateBuilder"] = Builder(
9-
action=env.Run(build_template_cs.make_templates),
10-
suffix=".h",
11-
src_suffix=".cs",
12-
)
13-
14-
# Template files
15-
templates_sources = Glob("*/*.cs")
16-
17-
env.Alias("editor_template_cs", [env.MakeCSharpTemplateBuilder("templates.gen.h", templates_sources)])
8+
env.CommandNoCache("templates.gen.h", Glob("*/*.cs"), env.Run(build_template_cs.make_templates))

modules/text_server_adv/SCsub

+3-2
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,9 @@ if env["builtin_icu4c"]:
479479
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
480480

481481
if env.editor_build:
482-
env_icu.Depends("#thirdparty/icu4c/icudata.gen.h", "#thirdparty/icu4c/icudt_godot.dat")
483-
env_icu.Command("#thirdparty/icu4c/icudata.gen.h", "#thirdparty/icu4c/icudt_godot.dat", make_icu_data)
482+
env_icu.CommandNoCache(
483+
"#thirdparty/icu4c/icudata.gen.h", "#thirdparty/icu4c/icudt_godot.dat", env.Run(make_icu_data)
484+
)
484485
env_text_server_adv.Prepend(CPPPATH=["#thirdparty/icu4c/"])
485486
else:
486487
thirdparty_sources += ["icu_data/icudata_stub.cpp"]

0 commit comments

Comments
 (0)