SCons: Add emitter to declutter build objects

This commit is contained in:
Thaddeus Crews 2025-01-13 11:13:17 -06:00
parent 0028fd625e
commit 10ed66f28c
No known key found for this signature in database
GPG key ID: 62181B86FE9E5D84
7 changed files with 50 additions and 11 deletions

View file

@ -16,8 +16,7 @@ from typing import Generator, List, Optional, Union, cast
from misc.utility.color import print_error, print_info, print_warning
# Get the "Godot" folder name ahead of time
base_folder_path = str(os.path.abspath(Path(__file__).parent)) + "/"
base_folder_only = os.path.basename(os.path.normpath(base_folder_path))
base_folder = Path(__file__).resolve().parent
compiler_version_cache = None
@ -83,6 +82,29 @@ def add_source_files(self, sources, files, allow_gen=False):
return True
def redirect_emitter(target, source, env):
"""
Emitter to automatically redirect object/library build files to the `bin/obj` directory,
retaining subfolder structure. External build files will attempt to retain subfolder
structure relative to their environment's parent directory, sorted under `bin/obj/external`.
If `redirect_build_objects` is `False`, or an external build file isn't relative to the
passed environment, this emitter does nothing.
"""
if not env["redirect_build_objects"]:
return target, source
redirected_targets = []
for item in target:
if base_folder in (path := Path(item.get_abspath()).resolve()).parents:
item = env.File(f"#bin/obj/{path.relative_to(base_folder)}")
elif (alt_base := Path(env.Dir(".").get_abspath()).resolve().parent) in path.parents:
item = env.File(f"#bin/obj/external/{path.relative_to(alt_base)}")
else:
print_warning(f'Failed to redirect "{path}"')
redirected_targets.append(item)
return redirected_targets, source
def disable_warnings(self):
# 'self' is the environment
if self.msvc and not using_clang(self):
@ -150,7 +172,7 @@ def get_version_info(module_version_string="", silent=False):
def get_git_info():
os.chdir(base_folder_path)
os.chdir(base_folder)
# Parse Git hash if we're in a Git repo.
git_hash = ""
@ -775,7 +797,7 @@ def show_progress(env):
if env["ninja"]:
return
NODE_COUNT_FILENAME = f"{base_folder_path}.scons_node_count"
NODE_COUNT_FILENAME = base_folder / ".scons_node_count"
class ShowProgress:
def __init__(self):