Last active
April 27, 2025 18:03
-
-
Save adamscott/82f2c51b73253712fdc7cadf72810899 to your computer and use it in GitHub Desktop.
My own Godot "custom.py" (useful default values and caching system for older versions)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from misc.utility.scons_hints import * | |
import distutils | |
import os | |
import platform as platform_module | |
from SCons.Script import ARGUMENTS | |
from SCons.Variables.BoolVariable import TRUE_STRINGS | |
def has_command_line_tool(name): | |
from shutil import which | |
return which(name) is not None | |
def has_cache_tool_commit(): | |
from subprocess import run | |
CACHE_TOOL_COMMIT = "0e4a4e3c4d602691ce1b4fc6a721c5c637ead57f" | |
result = run(["git", "merge-base", "--is-ancestor", CACHE_TOOL_COMMIT, "HEAD"]) | |
return result.returncode == 0 | |
def get_active_branch_name(): | |
from subprocess import run | |
result = run(["git", "rev-parse", "--abbrev-ref", "HEAD"], capture_output=True, text=True) | |
return result.stdout.strip() | |
if ARGUMENTS.get("custom", "yes") in TRUE_STRINGS: | |
system = platform_module.system() | |
compiledb = ARGUMENTS.get("compiledb", "yes") | |
_current_platform = None | |
if len(platform_module.mac_ver()[0]) > 0: | |
_current_platform = "macos" | |
elif system == "Linux" or system == "FreeBSD": | |
_current_platform = "linux" | |
elif len(platform_module.win32_ver()[0]) > 0: | |
_current_platform = "windows" | |
if _current_platform is not None: | |
platform = ARGUMENTS.get("platform", _current_platform) | |
dev_build = ARGUMENTS.get("dev_build", "yes") | |
dev_mode = ARGUMENTS.get("dev_mode", "yes") | |
scu_build = ARGUMENTS.get("scu_build", "yes") | |
fast_unsafe = ARGUMENTS.get("fast_unsafe", "yes") | |
target = ARGUMENTS.get("target", "editor") | |
module_mono_enabled = ARGUMENTS.get("module_mono_enabled", "no") | |
verbose = ARGUMENTS.get("verbose", "yes") | |
# debug_symbols = ARGUMENTS.get("debug_symbols", "yes") | |
# separate_debug_symbols = ARGUMENTS.get("separate_debug_symbols", "yes") | |
if platform == "web": | |
webgpu = ARGUMENTS.get("webgpu", "yes") | |
if "DAWN_LIBS" in os.environ: | |
dawn_libs = os.environ["DAWN_LIBS"] | |
if "EMSCRIPTEN_INCLUDE_PATH" in os.environ: | |
emscripten_include_path = os.environ["EMSCRIPTEN_INCLUDE_PATH"] | |
if target == "template_debug" or target == "template_release": | |
dev_mode = False | |
optimize = ARGUMENTS.get("optimize", "size") | |
if platform == "web": | |
threads = ARGUMENTS.get("threads", "no") | |
dev_build = ARGUMENTS.get("dev_build", "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 | |
elif platform == "macos": | |
generate_bundle = ARGUMENTS.get("generate_bundle", "yes") | |
elif platform == "windows": | |
d3d12 = ARGUMENTS.get("d3d12", "yes") | |
if has_command_line_tool("git"): | |
_cache_dir_name = ".scons_cache" | |
_active_branch_name = get_active_branch_name() | |
if not ( | |
_active_branch_name == "master" | |
and (_current_platform is None or _current_platform == platform) | |
and target == "editor" | |
): | |
_cache_dir_name = f".scons_cache__{_active_branch_name}__{platform}__{target}" | |
_base_cache_path = os.path.join(os.getcwd(), ".scons_cache") | |
_cache_path = os.path.join(os.getcwd(), _cache_dir_name) | |
if (_base_cache_path != _cache_path) and (not os.path.isdir(_cache_path)) and (os.path.isdir(_base_cache_path)): | |
distutils.dir_util.copy_tree(_base_cache_path, _cache_path) | |
if has_cache_tool_commit(): | |
cache_path = ARGUMENTS.get("cache_path", _cache_dir_name) | |
cache_limit = ARGUMENTS.get("cache_limit", 5) | |
else: | |
print( | |
"INFO: This branch don't support `cache_path` and `cache_limit` parameters. Interfacing directly with SCons for cache." | |
) | |
if not os.getenv("SCONS_CACHE_LIMIT"): | |
os.environ["SCONS_CACHE_LIMIT"] = "5120" | |
if not os.getenv("SCONS_CACHE"): | |
os.environ["SCONS_CACHE"] = _cache_path | |
else: | |
print("WARNING: Skipping caching. custom.py needs `git`.") | |
# Variable clean-up. | |
del _cache_dir_name | |
del _active_branch_name | |
del _base_cache_path | |
del _cache_path | |
del distutils | |
del platform_module | |
del os | |
del ARGUMENTS | |
del TRUE_STRINGS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment