Skip to content

Instantly share code, notes, and snippets.

@adamscott
Last active June 29, 2024 18:14
Show Gist options
  • Save adamscott/82f2c51b73253712fdc7cadf72810899 to your computer and use it in GitHub Desktop.
Save adamscott/82f2c51b73253712fdc7cadf72810899 to your computer and use it in GitHub Desktop.
Local cache system for Godot branch builds
from distutils.dir_util import copy_tree
from os import environ, getenv, getcwd, path
import platform
from SCons.Script import ARGUMENTS
from SCons.Variables.BoolVariable import TRUE_STRINGS
def get_active_branch_name():
from os import getcwd, path
head_dir = path.join(getcwd(), ".git", "HEAD")
with open(head_dir, "r") as f:
content = f.read().splitlines()
for line in content:
if line[0:4] == "ref:":
return line.partition("refs/heads/")[2]
if ARGUMENTS.get("custom", "yes") in TRUE_STRINGS:
system = platform.system()
compiledb = ARGUMENTS.get("compiledb", "yes")
if system == "Darwin":
platform = ARGUMENTS.get("platform", "macos")
elif system == "Linux":
platform = ARGUMENTS.get("platform", "linuxbsd")
dev_build = ARGUMENTS.get("dev_build", "yes")
dev_mode = ARGUMENTS.get("dev_mode", "yes")
scu_build = ARGUMENTS.get("scu_build", "no")
fast_unsafe = ARGUMENTS.get("fast_unsafe", "yes")
target = ARGUMENTS.get("target", "editor")
module_mono_enabled = ARGUMENTS.get("module_mono_enabled", "no")
# debug_symbols = ARGUMENTS.get("debug_symbols", "yes")
# separate_debug_symbols = ARGUMENTS.get("separate_debug_symbols", "yes")
if target == "template_debug" or target == "template_release":
dev_mode = False
optimize = ARGUMENTS.get("optimize", "size")
if platform == "web":
threads = ARGUMENTS.get("threads", "no")
else:
optimize = ARGUMENTS.get("optimize", "none")
if platform == "linuxbsd":
# Comment if you want to use clang instead of gcc
use_llvm = ARGUMENTS.get("use_llvm", "yes")
linker = ARGUMENTS.get("linker", "mold")
pass
if not getenv("SCONS_CACHE_LIMIT"):
environ["SCONS_CACHE_LIMIT"] = "5120"
if not getenv("SCONS_CACHE"):
base_cache_path = path.join(getcwd(), ".scons_cache")
environ["SCONS_CACHE"] = base_cache_path
branch_name = get_active_branch_name()
if branch_name != "master" and target != "editor":
cache_path = path.join(getcwd(), f".scons_cache__{branch_name}__{target}")
if (not path.isdir(cache_path)) and (path.isdir(base_cache_path)):
copy_tree(base_cache_path, cache_path)
environ["SCONS_CACHE"] = cache_path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment