mirror of
https://github.com/godotengine/godot.git
synced 2024-10-22 21:21:53 +00:00
Compare commits
4 Commits
e64e46c64e
...
2d25d09d8b
Author | SHA1 | Date | |
---|---|---|---|
|
2d25d09d8b | ||
|
533c616cb8 | ||
|
d5d509bbd6 | ||
|
c1e70e6cf0 |
|
@ -29,7 +29,6 @@ runs:
|
||||||
# 4. A partial match for the same base branch only (not ideal, matches any PR with the same base branch).
|
# 4. A partial match for the same base branch only (not ideal, matches any PR with the same base branch).
|
||||||
|
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ inputs.cache-name }}-${{ env.GODOT_BASE_BRANCH }}-${{ github.ref }}-${{ github.sha }}
|
|
||||||
${{ inputs.cache-name }}-${{ env.GODOT_BASE_BRANCH }}-${{ github.ref }}
|
${{ inputs.cache-name }}-${{ env.GODOT_BASE_BRANCH }}-${{ github.ref }}
|
||||||
${{ inputs.cache-name }}-${{ env.GODOT_BASE_BRANCH }}-refs/heads/${{ env.GODOT_BASE_BRANCH }}
|
${{ inputs.cache-name }}-${{ env.GODOT_BASE_BRANCH }}-refs/heads/${{ env.GODOT_BASE_BRANCH }}
|
||||||
${{ inputs.cache-name }}-${{ env.GODOT_BASE_BRANCH }}
|
${{ inputs.cache-name }}-${{ env.GODOT_BASE_BRANCH }}
|
||||||
|
|
19
SConstruct
19
SConstruct
|
@ -1048,10 +1048,19 @@ GLSL_BUILDERS = {
|
||||||
}
|
}
|
||||||
env.Append(BUILDERS=GLSL_BUILDERS)
|
env.Append(BUILDERS=GLSL_BUILDERS)
|
||||||
|
|
||||||
scons_cache_path = os.environ.get("SCONS_CACHE")
|
env["SCONS_CACHE"] = os.environ.get("SCONS_CACHE", "")
|
||||||
if scons_cache_path is not None:
|
env["SCONS_CACHE_LIMIT"] = int(os.getenv("SCONS_CACHE_LIMIT", 1024)) * 1024 * 1024
|
||||||
CacheDir(scons_cache_path)
|
|
||||||
print("Scons cache enabled... (path: '" + scons_cache_path + "')")
|
if env["SCONS_CACHE"]:
|
||||||
|
CacheDir(env["SCONS_CACHE"])
|
||||||
|
print(f'Scons cache enabled... (path: "{env["SCONS_CACHE"]}")')
|
||||||
|
if env["verbose"]:
|
||||||
|
print(
|
||||||
|
"Current cache limit is {} (used: {})".format(
|
||||||
|
methods.convert_size(env["SCONS_CACHE_LIMIT"]),
|
||||||
|
methods.convert_size(methods.get_size(env["SCONS_CACHE"])),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if env["vsproj"]:
|
if env["vsproj"]:
|
||||||
env.vs_incs = []
|
env.vs_incs = []
|
||||||
|
@ -1147,4 +1156,4 @@ def purge_flaky_files():
|
||||||
|
|
||||||
atexit.register(purge_flaky_files)
|
atexit.register(purge_flaky_files)
|
||||||
|
|
||||||
methods.clean_cache(env)
|
atexit.register(methods.clean_cache, env)
|
||||||
|
|
216
methods.py
216
methods.py
|
@ -1,5 +1,6 @@
|
||||||
import contextlib
|
import contextlib
|
||||||
import glob
|
import glob
|
||||||
|
import math
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -903,160 +904,109 @@ def using_emcc(env):
|
||||||
return "emcc" in os.path.basename(env["CC"])
|
return "emcc" in os.path.basename(env["CC"])
|
||||||
|
|
||||||
|
|
||||||
|
def convert_size(size_bytes: int) -> str:
|
||||||
|
if size_bytes == 0:
|
||||||
|
return "0 bytes"
|
||||||
|
SIZE_NAMES = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
|
||||||
|
index = int(math.floor(math.log(size_bytes, 1024)))
|
||||||
|
power = math.pow(1024, index)
|
||||||
|
size = round(size_bytes / power, 2)
|
||||||
|
return f"{size} {SIZE_NAMES[index]}"
|
||||||
|
|
||||||
|
|
||||||
|
def get_size(start_path: str = ".") -> int:
|
||||||
|
total_size = 0
|
||||||
|
for dirpath, _, filenames in os.walk(start_path):
|
||||||
|
for file in filenames:
|
||||||
|
path = os.path.join(dirpath, file)
|
||||||
|
total_size += os.path.getsize(path)
|
||||||
|
return total_size
|
||||||
|
|
||||||
|
|
||||||
def show_progress(env):
|
def show_progress(env):
|
||||||
if env["ninja"]:
|
# Progress reporting is not available in non-TTY environments since it messes with the output
|
||||||
# Has its own progress/tracking tool that clashes with ours
|
# (for example, when writing to a file). Ninja has its own progress/tracking tool that clashes
|
||||||
|
# with ours.
|
||||||
|
if not env["progress"] or not sys.stdout.isatty() or env["ninja"]:
|
||||||
return
|
return
|
||||||
|
|
||||||
import sys
|
NODE_COUNT_FILENAME = f"{base_folder_path}.scons_node_count"
|
||||||
|
|
||||||
from SCons.Script import AlwaysBuild, Command, Progress
|
class ShowProgress:
|
||||||
|
def __init__(self):
|
||||||
screen = sys.stdout
|
self.count = 0
|
||||||
# Progress reporting is not available in non-TTY environments since it
|
self.max = 0
|
||||||
# messes with the output (for example, when writing to a file)
|
try:
|
||||||
show_progress = env["progress"] and sys.stdout.isatty()
|
with open(NODE_COUNT_FILENAME, "r", encoding="utf-8") as f:
|
||||||
node_count = 0
|
self.max = int(f.readline())
|
||||||
node_count_max = 0
|
except OSError:
|
||||||
node_count_interval = 1
|
pass
|
||||||
node_count_fname = str(env.Dir("#")) + "/.scons_node_count"
|
if self.max == 0:
|
||||||
|
print("NOTE: Performing initial build, progress percentage unavailable!")
|
||||||
import math
|
|
||||||
|
|
||||||
class cache_progress:
|
|
||||||
# The default is 1 GB cache
|
|
||||||
def __init__(self, path=None, limit=pow(1024, 3)):
|
|
||||||
self.path = path
|
|
||||||
self.limit = limit
|
|
||||||
if env["verbose"] and path is not None:
|
|
||||||
screen.write(
|
|
||||||
"Current cache limit is {} (used: {})\n".format(
|
|
||||||
self.convert_size(limit), self.convert_size(self.get_size(path))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def __call__(self, node, *args, **kw):
|
def __call__(self, node, *args, **kw):
|
||||||
nonlocal node_count, node_count_max, node_count_interval, node_count_fname, show_progress
|
self.count += 1
|
||||||
if show_progress:
|
if self.max != 0:
|
||||||
# Print the progress percentage
|
percent = int(min(self.count * 100 / self.max, 100))
|
||||||
node_count += node_count_interval
|
sys.stdout.write(f"\r[{percent:3d}%] ")
|
||||||
if node_count_max > 0 and node_count <= node_count_max:
|
sys.stdout.flush()
|
||||||
screen.write("\r[%3d%%] " % (node_count * 100 / node_count_max))
|
|
||||||
screen.flush()
|
|
||||||
elif node_count_max > 0 and node_count > node_count_max:
|
|
||||||
screen.write("\r[100%] ")
|
|
||||||
screen.flush()
|
|
||||||
else:
|
|
||||||
screen.write("\r[Initial build] ")
|
|
||||||
screen.flush()
|
|
||||||
|
|
||||||
def convert_size(self, size_bytes):
|
from SCons.Script import Progress
|
||||||
if size_bytes == 0:
|
|
||||||
return "0 bytes"
|
|
||||||
size_name = ("bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
|
|
||||||
i = int(math.floor(math.log(size_bytes, 1024)))
|
|
||||||
p = math.pow(1024, i)
|
|
||||||
s = round(size_bytes / p, 2)
|
|
||||||
return "%s %s" % (int(s) if i == 0 else s, size_name[i])
|
|
||||||
|
|
||||||
def get_size(self, start_path="."):
|
progressor = ShowProgress()
|
||||||
total_size = 0
|
Progress(progressor)
|
||||||
for dirpath, dirnames, filenames in os.walk(start_path):
|
|
||||||
for f in filenames:
|
|
||||||
fp = os.path.join(dirpath, f)
|
|
||||||
total_size += os.path.getsize(fp)
|
|
||||||
return total_size
|
|
||||||
|
|
||||||
def progress_finish(target, source, env):
|
def progress_finish(target, source, env):
|
||||||
nonlocal node_count, progressor
|
|
||||||
try:
|
try:
|
||||||
with open(node_count_fname, "w", encoding="utf-8", newline="\n") as f:
|
with open(NODE_COUNT_FILENAME, "w", encoding="utf-8", newline="\n") as f:
|
||||||
f.write("%d\n" % node_count)
|
f.write(f"{progressor.count}\n")
|
||||||
except Exception:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
env.AlwaysBuild(
|
||||||
with open(node_count_fname, "r", encoding="utf-8") as f:
|
env.CommandNoCache(
|
||||||
node_count_max = int(f.readline())
|
"progress_finish", [], env.Action(progress_finish, "Building node count database .scons_node_count")
|
||||||
except Exception:
|
)
|
||||||
pass
|
)
|
||||||
|
|
||||||
cache_directory = os.environ.get("SCONS_CACHE")
|
|
||||||
# Simple cache pruning, attached to SCons' progress callback. Trim the
|
|
||||||
# cache directory to a size not larger than cache_limit.
|
|
||||||
cache_limit = float(os.getenv("SCONS_CACHE_LIMIT", 1024)) * 1024 * 1024
|
|
||||||
progressor = cache_progress(cache_directory, cache_limit)
|
|
||||||
Progress(progressor, interval=node_count_interval)
|
|
||||||
|
|
||||||
progress_finish_command = Command("progress_finish", [], progress_finish)
|
|
||||||
AlwaysBuild(progress_finish_command)
|
|
||||||
|
|
||||||
|
|
||||||
def clean_cache(env):
|
def clean_cache(env):
|
||||||
import atexit
|
if env.GetOption("clean") or not env["SCONS_CACHE"]:
|
||||||
import time
|
return
|
||||||
|
|
||||||
class cache_clean:
|
files = glob.glob(os.path.join(env["SCONS_CACHE"], "*", "*"))
|
||||||
def __init__(self, path=None, limit=pow(1024, 3)):
|
if not files:
|
||||||
self.path = path
|
return
|
||||||
self.limit = limit
|
|
||||||
|
|
||||||
def clean(self):
|
# Remove all text files, store binary files in list of (filename, size, atime).
|
||||||
self.delete(self.file_list())
|
purge = []
|
||||||
|
stats = []
|
||||||
def delete(self, files):
|
for file in files:
|
||||||
if len(files) == 0:
|
# A bit of an antipattern, but failing a utf-8 decode is the easiest way to determine if
|
||||||
return
|
# a file is binary.
|
||||||
if env["verbose"]:
|
|
||||||
# Utter something
|
|
||||||
print("Purging %d %s from cache..." % (len(files), "files" if len(files) > 1 else "file"))
|
|
||||||
[os.remove(f) for f in files]
|
|
||||||
|
|
||||||
def file_list(self):
|
|
||||||
if self.path is None:
|
|
||||||
# Nothing to do
|
|
||||||
return []
|
|
||||||
# Gather a list of (filename, (size, atime)) within the
|
|
||||||
# cache directory
|
|
||||||
file_stat = [(x, os.stat(x)[6:8]) for x in glob.glob(os.path.join(self.path, "*", "*"))]
|
|
||||||
if file_stat == []:
|
|
||||||
# Nothing to do
|
|
||||||
return []
|
|
||||||
# Weight the cache files by size (assumed to be roughly
|
|
||||||
# proportional to the recompilation time) times an exponential
|
|
||||||
# decay since the ctime, and return a list with the entries
|
|
||||||
# (filename, size, weight).
|
|
||||||
current_time = time.time()
|
|
||||||
file_stat = [(x[0], x[1][0], (current_time - x[1][1])) for x in file_stat]
|
|
||||||
# Sort by the most recently accessed files (most sensible to keep) first
|
|
||||||
file_stat.sort(key=lambda x: x[2])
|
|
||||||
# Search for the first entry where the storage limit is
|
|
||||||
# reached
|
|
||||||
sum, mark = 0, None
|
|
||||||
for i, x in enumerate(file_stat):
|
|
||||||
sum += x[1]
|
|
||||||
if sum > self.limit:
|
|
||||||
mark = i
|
|
||||||
break
|
|
||||||
if mark is None:
|
|
||||||
return []
|
|
||||||
else:
|
|
||||||
return [x[0] for x in file_stat[mark:]]
|
|
||||||
|
|
||||||
def cache_finally():
|
|
||||||
nonlocal cleaner
|
|
||||||
try:
|
try:
|
||||||
cleaner.clean()
|
with open(file, encoding="utf-8") as out:
|
||||||
except Exception:
|
out.read(100)
|
||||||
pass
|
purge.append(file)
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
stats.append((file, *os.stat(file)[6:8]))
|
||||||
|
|
||||||
cache_directory = os.environ.get("SCONS_CACHE")
|
# Sort by most recent access (most sensible to keep) first. Search for the first entry where
|
||||||
# Simple cache pruning, attached to SCons' progress callback. Trim the
|
# the cache limit is reached.
|
||||||
# cache directory to a size not larger than cache_limit.
|
stats.sort(key=lambda x: x[2], reverse=True)
|
||||||
cache_limit = float(os.getenv("SCONS_CACHE_LIMIT", 1024)) * 1024 * 1024
|
cache_limit = env["SCONS_CACHE_LIMIT"]
|
||||||
cleaner = cache_clean(cache_directory, cache_limit)
|
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
|
||||||
|
|
||||||
atexit.register(cache_finally)
|
if purge:
|
||||||
|
if env["verbose"]:
|
||||||
|
print("Purging %d %s from cache..." % (len(purge), "files" if len(purge) > 1 else "file"))
|
||||||
|
for file in purge:
|
||||||
|
os.remove(file)
|
||||||
|
|
||||||
|
|
||||||
def dump(env):
|
def dump(env):
|
||||||
|
|
|
@ -7260,6 +7260,10 @@ void RenderingDevice::_bind_methods() {
|
||||||
BIND_ENUM_CONSTANT(DEBUG_PASS);
|
BIND_ENUM_CONSTANT(DEBUG_PASS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderingDevice::make_current() {
|
||||||
|
render_thread_id = Thread::get_caller_id();
|
||||||
|
}
|
||||||
|
|
||||||
RenderingDevice::~RenderingDevice() {
|
RenderingDevice::~RenderingDevice() {
|
||||||
finalize();
|
finalize();
|
||||||
|
|
||||||
|
|
|
@ -1496,6 +1496,8 @@ public:
|
||||||
|
|
||||||
static RenderingDevice *get_singleton();
|
static RenderingDevice *get_singleton();
|
||||||
|
|
||||||
|
void make_current();
|
||||||
|
|
||||||
RenderingDevice();
|
RenderingDevice();
|
||||||
~RenderingDevice();
|
~RenderingDevice();
|
||||||
|
|
||||||
|
|
|
@ -370,6 +370,8 @@ Size2i RenderingServerDefault::get_maximum_viewport_size() const {
|
||||||
void RenderingServerDefault::_assign_mt_ids(WorkerThreadPool::TaskID p_pump_task_id) {
|
void RenderingServerDefault::_assign_mt_ids(WorkerThreadPool::TaskID p_pump_task_id) {
|
||||||
server_thread = Thread::get_caller_id();
|
server_thread = Thread::get_caller_id();
|
||||||
server_task_id = p_pump_task_id;
|
server_task_id = p_pump_task_id;
|
||||||
|
// This is needed because the main RD is created on the main thread.
|
||||||
|
RenderingDevice::get_singleton()->make_current();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderingServerDefault::_thread_exit() {
|
void RenderingServerDefault::_thread_exit() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user