Skip to content

Commit

Permalink
Refactor module loading logic to be more SConsish
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Babiichuk (DustDFG) <dfgdust@gmail.com>
  • Loading branch information
dustdfg committed Nov 20, 2024
1 parent 5c9f608 commit 418426b
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,6 @@ def force_optimization_on_debug(self):
self.AppendUnique(CCFLAGS=["-O3"])


def add_module_version_string(self, s):
self.module_version_string += "." + s


def get_version_info(module_version_string="", silent=False):
build_name = "custom_build"
if os.getenv("BUILD_NAME") is not None:
Expand Down Expand Up @@ -254,6 +250,11 @@ def get_cmdline_bool(option, default):
return default


############################################################
# MODULE LOADING
############################################################


def detect_modules(search_path, recursive=False):
"""Detects and collects a list of C++ modules at specified path
Expand All @@ -270,22 +271,22 @@ def detect_modules(search_path, recursive=False):
values. If a path is relative, then it is a built-in module. If a path is
absolute, then it is a custom module collected outside of the engine source.
"""

from SCons.Script import Dir

engine_dir = Dir("#").get_abspath()
modules = OrderedDict()

def add_module(path):
module_name = os.path.basename(path)
module_path = path.replace("\\", "/") # win32
module_path = Dir(path).get_relpath()
module_name = os.path.basename(module_path)
modules[module_name] = module_path

def is_engine(path):
# Prevent recursively detecting modules in self and other
# Godot sources when using `custom_modules` build option.
version_path = os.path.join(path, "version.py")
if os.path.exists(version_path):
with open(version_path, "r", encoding="utf-8") as f:
if 'short_name = "godot"' in f.read():
return True
return False
if os.path.isdir(path):
return engine_dir == Dir(path).get_abspath()

def get_files(path):
files = glob.glob(os.path.join(path, "*"))
Expand Down Expand Up @@ -363,7 +364,7 @@ def module_check_dependencies(self, module):
missing_deps = set()
required_deps = self.module_dependencies[module][0] if module in self.module_dependencies else []
for dep in required_deps:
opt = "module_{}_enabled".format(dep)
opt = f"module_{dep}_enabled"
if opt not in self or not self[opt] or not module_check_dependencies(self, dep):
missing_deps.add(dep)

Expand Down Expand Up @@ -397,6 +398,10 @@ def sort_module_list(env):
env.module_list.move_to_end(k)


def add_module_version_string(self, s):
self.module_version_string += "." + s


def use_windows_spawn_fix(self, platform=None):
if os.name != "nt":
return # not needed, only for windows
Expand Down

0 comments on commit 418426b

Please sign in to comment.