SCons: Convert `env_base` to `env`

This commit is contained in:
Thaddeus Crews 2024-04-17 12:26:20 -05:00
parent 4b7776e31b
commit 41fee42c40
No known key found for this signature in database
GPG Key ID: 62181B86FE9E5D84
1 changed files with 77 additions and 79 deletions

View File

@ -121,38 +121,38 @@ elif os.name == "nt" and methods.get_cmdline_bool("use_mingw", False):
# We let SCons build its default ENV as it includes OS-specific things which we don't # We let SCons build its default ENV as it includes OS-specific things which we don't
# want to have to pull in manually. # want to have to pull in manually.
# Then we prepend PATH to make it take precedence, while preserving SCons' own entries. # Then we prepend PATH to make it take precedence, while preserving SCons' own entries.
env_base = Environment(tools=custom_tools) env = Environment(tools=custom_tools)
env_base.PrependENVPath("PATH", os.getenv("PATH")) env.PrependENVPath("PATH", os.getenv("PATH"))
env_base.PrependENVPath("PKG_CONFIG_PATH", os.getenv("PKG_CONFIG_PATH")) env.PrependENVPath("PKG_CONFIG_PATH", os.getenv("PKG_CONFIG_PATH"))
if "TERM" in os.environ: # Used for colored output. if "TERM" in os.environ: # Used for colored output.
env_base["ENV"]["TERM"] = os.environ["TERM"] env["ENV"]["TERM"] = os.environ["TERM"]
env_base.disabled_modules = [] env.disabled_modules = []
env_base.module_version_string = "" env.module_version_string = ""
env_base.msvc = False env.msvc = False
env_base.__class__.disable_module = methods.disable_module env.__class__.disable_module = methods.disable_module
env_base.__class__.add_module_version_string = methods.add_module_version_string env.__class__.add_module_version_string = methods.add_module_version_string
env_base.__class__.add_source_files = methods.add_source_files env.__class__.add_source_files = methods.add_source_files
env_base.__class__.use_windows_spawn_fix = methods.use_windows_spawn_fix env.__class__.use_windows_spawn_fix = methods.use_windows_spawn_fix
env_base.__class__.add_shared_library = methods.add_shared_library env.__class__.add_shared_library = methods.add_shared_library
env_base.__class__.add_library = methods.add_library env.__class__.add_library = methods.add_library
env_base.__class__.add_program = methods.add_program env.__class__.add_program = methods.add_program
env_base.__class__.CommandNoCache = methods.CommandNoCache env.__class__.CommandNoCache = methods.CommandNoCache
env_base.__class__.Run = methods.Run env.__class__.Run = methods.Run
env_base.__class__.disable_warnings = methods.disable_warnings env.__class__.disable_warnings = methods.disable_warnings
env_base.__class__.force_optimization_on_debug = methods.force_optimization_on_debug env.__class__.force_optimization_on_debug = methods.force_optimization_on_debug
env_base.__class__.module_add_dependencies = methods.module_add_dependencies env.__class__.module_add_dependencies = methods.module_add_dependencies
env_base.__class__.module_check_dependencies = methods.module_check_dependencies env.__class__.module_check_dependencies = methods.module_check_dependencies
env_base["x86_libtheora_opt_gcc"] = False env["x86_libtheora_opt_gcc"] = False
env_base["x86_libtheora_opt_vc"] = False env["x86_libtheora_opt_vc"] = False
# avoid issues when building with different versions of python out of the same directory # avoid issues when building with different versions of python out of the same directory
env_base.SConsignFile(File("#.sconsign{0}.dblite".format(pickle.HIGHEST_PROTOCOL)).abspath) env.SConsignFile(File("#.sconsign{0}.dblite".format(pickle.HIGHEST_PROTOCOL)).abspath)
# Build options # Build options
@ -275,22 +275,22 @@ opts.Add("linkflags", "Custom flags for the linker")
# Update the environment to have all above options defined # Update the environment to have all above options defined
# in following code (especially platform and custom_modules). # in following code (especially platform and custom_modules).
opts.Update(env_base) opts.Update(env)
# Copy custom environment variables if set. # Copy custom environment variables if set.
if env_base["import_env_vars"]: if env["import_env_vars"]:
for env_var in str(env_base["import_env_vars"]).split(","): for env_var in str(env["import_env_vars"]).split(","):
if env_var in os.environ: if env_var in os.environ:
env_base["ENV"][env_var] = os.environ[env_var] env["ENV"][env_var] = os.environ[env_var]
# Platform selection: validate input, and add options. # Platform selection: validate input, and add options.
selected_platform = "" selected_platform = ""
if env_base["platform"] != "": if env["platform"] != "":
selected_platform = env_base["platform"] selected_platform = env["platform"]
elif env_base["p"] != "": elif env["p"] != "":
selected_platform = env_base["p"] selected_platform = env["p"]
else: else:
# Missing `platform` argument, try to detect platform automatically # Missing `platform` argument, try to detect platform automatically
if ( if (
@ -343,7 +343,7 @@ if selected_platform not in platform_list:
# Make sure to update this to the found, valid platform as it's used through the buildsystem as the reference. # Make sure to update this to the found, valid platform as it's used through the buildsystem as the reference.
# It should always be re-set after calling `opts.Update()` otherwise it uses the original input value. # It should always be re-set after calling `opts.Update()` otherwise it uses the original input value.
env_base["platform"] = selected_platform env["platform"] = selected_platform
# Add platform-specific options. # Add platform-specific options.
if selected_platform in platform_opts: if selected_platform in platform_opts:
@ -351,15 +351,15 @@ if selected_platform in platform_opts:
opts.Add(opt) opts.Add(opt)
# Update the environment to take platform-specific options into account. # Update the environment to take platform-specific options into account.
opts.Update(env_base) opts.Update(env)
env_base["platform"] = selected_platform # Must always be re-set after calling opts.Update(). env["platform"] = selected_platform # Must always be re-set after calling opts.Update().
# Detect modules. # Detect modules.
modules_detected = OrderedDict() modules_detected = OrderedDict()
module_search_paths = ["modules"] # Built-in path. module_search_paths = ["modules"] # Built-in path.
if env_base["custom_modules"]: if env["custom_modules"]:
paths = env_base["custom_modules"].split(",") paths = env["custom_modules"].split(",")
for p in paths: for p in paths:
try: try:
module_search_paths.append(methods.convert_custom_modules_path(p)) module_search_paths.append(methods.convert_custom_modules_path(p))
@ -373,13 +373,13 @@ for path in module_search_paths:
# so save the time it takes to parse directories. # so save the time it takes to parse directories.
modules = methods.detect_modules(path, recursive=False) modules = methods.detect_modules(path, recursive=False)
else: # Custom. else: # Custom.
modules = methods.detect_modules(path, env_base["custom_modules_recursive"]) modules = methods.detect_modules(path, env["custom_modules_recursive"])
# Provide default include path for both the custom module search `path` # Provide default include path for both the custom module search `path`
# and the base directory containing custom modules, as it may be different # and the base directory containing custom modules, as it may be different
# from the built-in "modules" name (e.g. "custom_modules/summator/summator.h"), # from the built-in "modules" name (e.g. "custom_modules/summator/summator.h"),
# so it can be referenced simply as `#include "summator/summator.h"` # so it can be referenced simply as `#include "summator/summator.h"`
# independently of where a module is located on user's filesystem. # independently of where a module is located on user's filesystem.
env_base.Prepend(CPPPATH=[path, os.path.dirname(path)]) env.Prepend(CPPPATH=[path, os.path.dirname(path)])
# Note: custom modules can override built-in ones. # Note: custom modules can override built-in ones.
modules_detected.update(modules) modules_detected.update(modules)
@ -388,7 +388,7 @@ for name, path in modules_detected.items():
sys.path.insert(0, path) sys.path.insert(0, path)
import config import config
if env_base["modules_enabled_by_default"]: if env["modules_enabled_by_default"]:
enabled = True enabled = True
try: try:
enabled = config.is_enabled() enabled = config.is_enabled()
@ -412,17 +412,17 @@ for name, path in modules_detected.items():
methods.write_modules(modules_detected) methods.write_modules(modules_detected)
# Update the environment again after all the module options are added. # Update the environment again after all the module options are added.
opts.Update(env_base) opts.Update(env)
env_base["platform"] = selected_platform # Must always be re-set after calling opts.Update(). env["platform"] = selected_platform # Must always be re-set after calling opts.Update().
Help(opts.GenerateHelpText(env_base)) Help(opts.GenerateHelpText(env))
# add default include paths # add default include paths
env_base.Prepend(CPPPATH=["#"]) env.Prepend(CPPPATH=["#"])
# configure ENV for platform # configure ENV for platform
env_base.platform_exporters = platform_exporters env.platform_exporters = platform_exporters
env_base.platform_apis = platform_apis env.platform_apis = platform_apis
# Configuration of build targets: # Configuration of build targets:
# - Editor or template # - Editor or template
@ -431,71 +431,69 @@ env_base.platform_apis = platform_apis
# - Optimization level # - Optimization level
# - Debug symbols for crash traces / debuggers # - Debug symbols for crash traces / debuggers
env_base.editor_build = env_base["target"] == "editor" env.editor_build = env["target"] == "editor"
env_base.dev_build = env_base["dev_build"] env.dev_build = env["dev_build"]
env_base.debug_features = env_base["target"] in ["editor", "template_debug"] env.debug_features = env["target"] in ["editor", "template_debug"]
if env_base.dev_build: if env.dev_build:
opt_level = "none" opt_level = "none"
elif env_base.debug_features: elif env.debug_features:
opt_level = "speed_trace" opt_level = "speed_trace"
else: # Release else: # Release
opt_level = "speed" opt_level = "speed"
env_base["optimize"] = ARGUMENTS.get("optimize", opt_level) env["optimize"] = ARGUMENTS.get("optimize", opt_level)
env_base["debug_symbols"] = methods.get_cmdline_bool("debug_symbols", env_base.dev_build) env["debug_symbols"] = methods.get_cmdline_bool("debug_symbols", env.dev_build)
if env_base.editor_build: if env.editor_build:
env_base.Append(CPPDEFINES=["TOOLS_ENABLED"]) env.Append(CPPDEFINES=["TOOLS_ENABLED"])
if env_base.debug_features: if env.debug_features:
# DEBUG_ENABLED enables debugging *features* and debug-only code, which is intended # DEBUG_ENABLED enables debugging *features* and debug-only code, which is intended
# to give *users* extra debugging information for their game development. # to give *users* extra debugging information for their game development.
env_base.Append(CPPDEFINES=["DEBUG_ENABLED"]) env.Append(CPPDEFINES=["DEBUG_ENABLED"])
if env_base.dev_build: if env.dev_build:
# DEV_ENABLED enables *engine developer* code which should only be compiled for those # DEV_ENABLED enables *engine developer* code which should only be compiled for those
# working on the engine itself. # working on the engine itself.
env_base.Append(CPPDEFINES=["DEV_ENABLED"]) env.Append(CPPDEFINES=["DEV_ENABLED"])
else: else:
# Disable assert() for production targets (only used in thirdparty code). # Disable assert() for production targets (only used in thirdparty code).
env_base.Append(CPPDEFINES=["NDEBUG"]) env.Append(CPPDEFINES=["NDEBUG"])
# SCons speed optimization controlled by the `fast_unsafe` option, which provide # SCons speed optimization controlled by the `fast_unsafe` option, which provide
# more than 10 s speed up for incremental rebuilds. # more than 10 s speed up for incremental rebuilds.
# Unsafe as they reduce the certainty of rebuilding all changed files, so it's # Unsafe as they reduce the certainty of rebuilding all changed files, so it's
# enabled by default for `debug` builds, and can be overridden from command line. # enabled by default for `debug` builds, and can be overridden from command line.
# Ref: https://github.com/SCons/scons/wiki/GoFastButton # Ref: https://github.com/SCons/scons/wiki/GoFastButton
if methods.get_cmdline_bool("fast_unsafe", env_base.dev_build): if methods.get_cmdline_bool("fast_unsafe", env.dev_build):
# Renamed to `content-timestamp` in SCons >= 4.2, keeping MD5 for compat. # Renamed to `content-timestamp` in SCons >= 4.2, keeping MD5 for compat.
env_base.Decider("MD5-timestamp") env.Decider("MD5-timestamp")
env_base.SetOption("implicit_cache", 1) env.SetOption("implicit_cache", 1)
env_base.SetOption("max_drift", 60) env.SetOption("max_drift", 60)
if env_base["use_precise_math_checks"]: if env["use_precise_math_checks"]:
env_base.Append(CPPDEFINES=["PRECISE_MATH_CHECKS"]) env.Append(CPPDEFINES=["PRECISE_MATH_CHECKS"])
if env_base.editor_build and env_base["engine_update_check"]: if env.editor_build and env["engine_update_check"]:
env_base.Append(CPPDEFINES=["ENGINE_UPDATE_CHECK_ENABLED"]) env.Append(CPPDEFINES=["ENGINE_UPDATE_CHECK_ENABLED"])
if not env_base.File("#main/splash_editor.png").exists(): if not env.File("#main/splash_editor.png").exists():
# Force disabling editor splash if missing. # Force disabling editor splash if missing.
env_base["no_editor_splash"] = True env["no_editor_splash"] = True
if env_base["no_editor_splash"]: if env["no_editor_splash"]:
env_base.Append(CPPDEFINES=["NO_EDITOR_SPLASH"]) env.Append(CPPDEFINES=["NO_EDITOR_SPLASH"])
if not env_base["deprecated"]: if not env["deprecated"]:
env_base.Append(CPPDEFINES=["DISABLE_DEPRECATED"]) env.Append(CPPDEFINES=["DISABLE_DEPRECATED"])
if env_base["precision"] == "double": if env["precision"] == "double":
env_base.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"]) env.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"])
tmppath = "./platform/" + selected_platform tmppath = "./platform/" + selected_platform
sys.path.insert(0, tmppath) sys.path.insert(0, tmppath)
import detect import detect
env = env_base.Clone()
# Default num_jobs to local cpu count if not user specified. # Default num_jobs to local cpu count if not user specified.
# SCons has a peculiarity where user-specified options won't be overridden # SCons has a peculiarity where user-specified options won't be overridden
# by SetOption, so we can rely on this to know if we should use our default. # by SetOption, so we can rely on this to know if we should use our default.
@ -570,7 +568,7 @@ if env["production"]:
# Run SCU file generation script if in a SCU build. # Run SCU file generation script if in a SCU build.
if env["scu_build"]: if env["scu_build"]:
max_includes_per_scu = 8 max_includes_per_scu = 8
if env_base.dev_build == True: if env.dev_build == True:
max_includes_per_scu = 1024 max_includes_per_scu = 1024
read_scu_limit = int(env["scu_limit"]) read_scu_limit = int(env["scu_limit"])
@ -844,7 +842,7 @@ suffix += "." + env["target"]
if env.dev_build: if env.dev_build:
suffix += ".dev" suffix += ".dev"
if env_base["precision"] == "double": if env["precision"] == "double":
suffix += ".double" suffix += ".double"
suffix += "." + env["arch"] suffix += "." + env["arch"]