Skip to content

Commit

Permalink
SCons: Properly NoCache all text files
Browse files Browse the repository at this point in the history
  • Loading branch information
Repiteo committed Jan 16, 2025
1 parent d33da79 commit 73278bf
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 249 deletions.
3 changes: 3 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,9 @@ env.Append(BUILDERS=GLSL_BUILDERS)
if env["compiledb"]:
env.Tool("compilation_db")
env.Alias("compiledb", env.CompilationDatabase())
env.NoCache(env.CompilationDatabase())
if not env["verbose"]:
env["COMPILATIONDB_COMSTR"] = "$GENCOMSTR"

if env["ninja"]:
if env.scons_version < (4, 2, 0):
Expand Down
16 changes: 7 additions & 9 deletions editor/icons/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ import os

import editor_icons_builders

env["BUILDERS"]["MakeEditorIconsBuilder"] = Builder(
action=env.Run(editor_icons_builders.make_editor_icons_action),
suffix=".h",
src_suffix=".svg",
)

# Editor's own icons
icon_sources = Glob("*.svg")

# Module icons
for path in env.module_icons_paths:
if not os.path.isabs(path):
icon_sources += Glob("#" + path + "/*.svg") # Built-in.
icon_sources += Glob(f"#{path}/*.svg") # Built-in.
else:
icon_sources += Glob(path + "/*.svg") # Custom.
icon_sources += Glob(f"{path}/*.svg") # Custom.

env.Alias("editor_icons", [env.MakeEditorIconsBuilder("#editor/themes/editor_icons.gen.h", icon_sources)])
env.CommandNoCache(
"#editor/themes/editor_icons.gen.h",
icon_sources,
env.Run(editor_icons_builders.make_editor_icons_action),
)
1 change: 1 addition & 0 deletions gles3_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,5 +585,6 @@ def build_gles3_header(


def build_gles3_headers(target, source, env):
env.NoCache(target)
for x in source:
build_gles3_header(str(x), include="drivers/gles3/shader_gles3.h", class_suffix="GLES3")
2 changes: 2 additions & 0 deletions glsl_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class {out_file_class} : public ShaderRD {{


def build_rd_headers(target, source, env):
env.NoCache(target)
for x in source:
build_rd_header(filename=str(x))

Expand Down Expand Up @@ -205,5 +206,6 @@ def build_raw_header(


def build_raw_headers(target, source, env):
env.NoCache(target)
for x in source:
build_raw_header(filename=str(x))
71 changes: 23 additions & 48 deletions methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,64 +816,39 @@ def get_size(start_path: str = ".") -> int:
return total_size


def clean_cache(cache_path: str, cache_limit: int, verbose: bool):
def clean_cache(cache_path: str, cache_limit: int, verbose: bool) -> None:
if not cache_limit:
return

files = glob.glob(os.path.join(cache_path, "*", "*"))
if not files:
return

# Remove all text files, store binary files in list of (filename, size, atime).
purge = []
texts = []
# Store files in list of (filename, size, atime).
stats = []
for file in files:
try:
# Save file stats to rewrite after modifying.
tmp_stat = os.stat(file)
# Failing a utf-8 decode is the easiest way to determine if a file is binary.
try:
with open(file, encoding="utf-8") as out:
out.read(1024)
except UnicodeDecodeError:
stats.append((file, *tmp_stat[6:8]))
# Restore file stats after reading.
os.utime(file, (tmp_stat[7], tmp_stat[8]))
else:
texts.append(file)
stats.append((file, *os.stat(file)[6:8]))
except OSError:
print_error(f'Failed to access cache file "{file}"; skipping.')

if texts:
count = len(texts)
for file in texts:
try:
os.remove(file)
except OSError:
print_error(f'Failed to remove cache file "{file}"; skipping.')
count -= 1
if verbose:
print("Purging %d text %s from cache..." % (count, "files" if count > 1 else "file"))

if cache_limit:
# Sort by most recent access (most sensible to keep) first. Search for the first entry where
# the cache limit is reached.
stats.sort(key=lambda x: x[2], reverse=True)
sum = 0
for index, stat in enumerate(stats):
sum += stat[1]
if sum > cache_limit:
purge.extend([x[0] for x in stats[index:]])
break

if purge:
count = len(purge)
for file in purge:
try:
os.remove(file)
except OSError:
print_error(f'Failed to remove cache file "{file}"; skipping.')
count -= 1
if verbose:
print("Purging %d %s from cache..." % (count, "files" if count > 1 else "file"))
# Sort by most recent access (most sensible to keep) first. Search for the first entry where
# the cache limit is reached.
stats.sort(key=lambda x: x[2], reverse=True)
sum = 0
for index, stat in enumerate(stats):
sum += stat[1]
if sum > cache_limit:
purge = [x[0] for x in stats[index:]]
count = len(purge)
for file in purge:
try:
os.remove(file)
except OSError:
print_error(f'Failed to remove cache file "{file}"; skipping.')
count -= 1
if verbose:
print_info(f"Purged {count} file{'s' if count else ''} from cache.")


def prepare_cache(env) -> None:
Expand Down
11 changes: 1 addition & 10 deletions modules/gdscript/editor/script_templates/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,4 @@ Import("env")

import editor.template_builders as build_template_gd

env["BUILDERS"]["MakeGDTemplateBuilder"] = Builder(
action=env.Run(build_template_gd.make_templates),
suffix=".h",
src_suffix=".gd",
)

# Template files
templates_sources = Glob("*/*.gd")

env.Alias("editor_template_gd", [env.MakeGDTemplateBuilder("templates.gen.h", templates_sources)])
env.CommandNoCache("templates.gen.h", Glob("*/*.gd"), env.Run(build_template_gd.make_templates))
11 changes: 1 addition & 10 deletions modules/mono/editor/script_templates/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,4 @@ Import("env")

import editor.template_builders as build_template_cs

env["BUILDERS"]["MakeCSharpTemplateBuilder"] = Builder(
action=env.Run(build_template_cs.make_templates),
suffix=".h",
src_suffix=".cs",
)

# Template files
templates_sources = Glob("*/*.cs")

env.Alias("editor_template_cs", [env.MakeCSharpTemplateBuilder("templates.gen.h", templates_sources)])
env.CommandNoCache("templates.gen.h", Glob("*/*.cs"), env.Run(build_template_cs.make_templates))
5 changes: 3 additions & 2 deletions modules/text_server_adv/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,9 @@ if env["builtin_icu4c"]:
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]

if env.editor_build:
env_icu.Depends("#thirdparty/icu4c/icudata.gen.h", "#thirdparty/icu4c/icudt_godot.dat")
env_icu.Command("#thirdparty/icu4c/icudata.gen.h", "#thirdparty/icu4c/icudt_godot.dat", make_icu_data)
env_icu.CommandNoCache(
"#thirdparty/icu4c/icudata.gen.h", "#thirdparty/icu4c/icudt_godot.dat", env.Run(make_icu_data)
)
env_text_server_adv.Prepend(CPPPATH=["#thirdparty/icu4c/"])
else:
thirdparty_sources += ["icu_data/icudata_stub.cpp"]
Expand Down
Loading

0 comments on commit 73278bf

Please sign in to comment.