From a461bdc8ab9df283d3b3b56c2dcd570e97ab1174 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Morin Date: Wed, 31 Dec 2025 12:48:32 -0500 Subject: [PATCH] Add a new setting called debug_shell_startup. When enabled, it logs information about the shell startup sequence. Signed-off-by: Jean-Christophe Morin --- src/rez/config.py | 1 + src/rez/resolved_context.py | 6 +++++- src/rez/rezconfig.py | 3 +++ src/rez/shells.py | 16 +++++++++++++++- src/rezplugins/shell/_utils/powershell_base.py | 7 +++++++ src/rezplugins/shell/cmd.py | 7 +++++++ 6 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/rez/config.py b/src/rez/config.py index 453718f03..c639b6a06 100644 --- a/src/rez/config.py +++ b/src/rez/config.py @@ -479,6 +479,7 @@ def _parse_env_var(self, value): "debug_memcache": Bool, "debug_resolve_memcache": Bool, "debug_context_tracking": Bool, + "debug_shell_startup": Bool, "debug_all": Bool, "debug_none": Bool, "quiet": Bool, diff --git a/src/rez/resolved_context.py b/src/rez/resolved_context.py index 8ad89fe22..02c0f0f94 100644 --- a/src/rez/resolved_context.py +++ b/src/rez/resolved_context.py @@ -17,7 +17,7 @@ from rez.utils.data_utils import deep_del from rez.utils.filesystem import TempDirs, is_subdirectory, canonical_path from rez.utils.memcached import pool_memcached_connections -from rez.utils.logging_ import print_error, print_warning +from rez.utils.logging_ import print_debug, print_error, print_warning from rez.utils.which import which from rez.rex import RexExecutor, Python, OutputStyle, literal from rez.rex_bindings import VersionBinding, VariantBinding, \ @@ -1454,6 +1454,10 @@ def execute_shell(self, shell=None, parent_environ=None, rcfile=None, # write out the native context file context_code = executor.get_output() + + if config.debug("shell_startup"): + print_debug("Writing context to %s" % context_file) + with open(context_file, 'w', encoding="utf-8") as f: f.write(context_code) diff --git a/src/rez/rezconfig.py b/src/rez/rezconfig.py index 7870ea29c..9512a52b9 100644 --- a/src/rez/rezconfig.py +++ b/src/rez/rezconfig.py @@ -744,6 +744,9 @@ # Print debugging info when an AMPQ server is used in context tracking debug_context_tracking = False +# Print debugging info related to shell startup +debug_shell_startup = False + # Turn on all debugging messages debug_all = False diff --git a/src/rez/shells.py b/src/rez/shells.py index 6dfe6d676..d6f38ec2f 100644 --- a/src/rez/shells.py +++ b/src/rez/shells.py @@ -8,7 +8,7 @@ from rez.rex import RexExecutor, ActionInterpreter, OutputStyle from rez.util import shlex_join, is_non_string_iterable from rez.utils.which import which -from rez.utils.logging_ import print_warning +from rez.utils.logging_ import print_debug, print_warning from rez.utils.execution import Popen from rez.system import system from rez.exceptions import RezSystemError @@ -404,6 +404,10 @@ def _record_shell(ex, files, bind_rez=True, print_msg=False): def _write_shell(ex, filename): code = ex.get_output() target_file = os.path.join(tmpdir, filename) + + if config.debug("shell_startup"): + print_debug("Writing shell script to %s" % target_file) + with open(target_file, 'w') as f: f.write(code) return target_file @@ -467,6 +471,9 @@ def _create_ex(): print_msg=bind_rez) _write_shell(ex, os.path.basename(file_)) + if config.debug("shell_startup"): + print_debug("Setting $HOME for new shell to %s" % tmpdir) + executor.setenv("HOME", tmpdir) # keep history @@ -489,6 +496,10 @@ def _create_ex(): code = executor.get_output() target_file = os.path.join(tmpdir, "rez-shell.%s" % self.file_extension()) + + if config.debug("shell_startup"): + print_debug("Writing rez-shell to %s" % target_file) + with open(target_file, 'w') as f: f.write(code) @@ -503,6 +514,9 @@ def _create_ex(): cmd = pre_command cmd.extend([self.executable, target_file]) + if config.debug("shell_startup"): + print_debug("Launching shell with command: %s" % self.join(cmd)) + try: p = Popen(cmd, env=env, **Popen_args) except Exception as e: diff --git a/src/rezplugins/shell/_utils/powershell_base.py b/src/rezplugins/shell/_utils/powershell_base.py index 1e2481237..2bbda3f45 100644 --- a/src/rezplugins/shell/_utils/powershell_base.py +++ b/src/rezplugins/shell/_utils/powershell_base.py @@ -12,6 +12,7 @@ from rez.utils.platform_ import platform_ from rez.utils.execution import Popen from rez.util import shlex_join +from rez.utils.logging_ import print_debug from .windows import get_syspaths_from_registry, to_windows_path @@ -173,6 +174,9 @@ def _record_shell(ex, files, bind_rez=True, print_msg=False): target_file = os.path.join(tmpdir, "rez-shell.%s" % self.file_extension()) + if config.debug("shell_startup"): + print_debug("Writing shell script to %s" % target_file) + with open(target_file, 'w') as f: f.write(code) @@ -200,6 +204,9 @@ def _record_shell(ex, files, bind_rez=True, print_msg=False): if shell_command is None: cmd.insert(1, "-NoExit") + if config.debug("shell_startup"): + print_debug("Launching shell with command: %s" % self.join(cmd)) + p = Popen(cmd, env=env, **Popen_args) return p diff --git a/src/rezplugins/shell/cmd.py b/src/rezplugins/shell/cmd.py index ddf6f4833..5bf45185f 100644 --- a/src/rezplugins/shell/cmd.py +++ b/src/rezplugins/shell/cmd.py @@ -11,6 +11,7 @@ from rez.system import system from rez.utils.execution import Popen from rez.utils.platform_ import platform_ +from rez.utils.logging_ import print_debug from ._utils.windows import to_windows_path, get_syspaths_from_registry from functools import partial import os @@ -172,6 +173,9 @@ def _create_ex(): target_file = os.path.join(tmpdir, "rez-shell.%s" % self.file_extension()) + if config.debug("shell_startup"): + print_debug("Writing shell script to %s" % target_file) + with open(target_file, 'w') as f: f.write(code) @@ -193,6 +197,9 @@ def _create_ex(): else: cmd_flags = ['/Q', '/C'] + if config.debug("shell_startup"): + print_debug("Launching shell with command: %s" % self.join(cmd)) + cmd += [self.executable] cmd += cmd_flags cmd += ['call {}'.format(target_file)]