From 23737c48548ac5d4264ac36d63c515c98bfbbdfc Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Fri, 22 Oct 2021 04:33:04 +0000 Subject: [PATCH] Bug 1736950 - Fix mach show-log after bug 1696251. r=firefox-build-system-reviewers,mhentges And disable logging on mach clobber like before. Differential Revision: https://phabricator.services.mozilla.com/D129104 --- python/mach/mach/decorators.py | 11 ++++++++++- python/mozbuild/mozbuild/base.py | 4 ++-- python/mozbuild/mozbuild/mach_commands.py | 9 ++++----- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/python/mach/mach/decorators.py b/python/mach/mach/decorators.py index 8ef234216291..dcaffab6bae8 100644 --- a/python/mach/mach/decorators.py +++ b/python/mach/mach/decorators.py @@ -43,6 +43,8 @@ class _MachCommand(object): # For subcommands, the global order that the subcommand's declaration # was seen. "decl_order", + # Whether to disable automatic logging to last_log.json for the command. + "no_auto_log", ) def __init__( @@ -56,6 +58,7 @@ class _MachCommand(object): order=None, virtualenv_name=None, ok_if_tests_disabled=False, + no_auto_log=False, ): self.name = name self.subcommand = subcommand @@ -77,6 +80,7 @@ class _MachCommand(object): self.metrics_path = None self.subcommand_handlers = {} self.decl_order = None + self.no_auto_log = no_auto_log def create_instance(self, context, virtualenv_name): metrics = None @@ -86,7 +90,12 @@ class _MachCommand(object): # This ensures the resulting class is defined inside `mach` so that logging # works as expected, and has a meaningful name subclass = type(self.name, (MachCommandBase,), {}) - return subclass(context, virtualenv_name=virtualenv_name, metrics=metrics) + return subclass( + context, + virtualenv_name=virtualenv_name, + metrics=metrics, + no_auto_log=self.no_auto_log, + ) @property def parser(self): diff --git a/python/mozbuild/mozbuild/base.py b/python/mozbuild/mozbuild/base.py index f4f1522c98eb..bca033afd908 100644 --- a/python/mozbuild/mozbuild/base.py +++ b/python/mozbuild/mozbuild/base.py @@ -896,7 +896,7 @@ class MachCommandBase(MozbuildObject): without having to change everything that inherits from it. """ - def __init__(self, context, virtualenv_name=None, metrics=None): + def __init__(self, context, virtualenv_name=None, metrics=None, no_auto_log=False): # Attempt to discover topobjdir through environment detection, as it is # more reliable than mozconfig when cwd is inside an objdir. topsrcdir = context.topdir @@ -970,7 +970,7 @@ class MachCommandBase(MozbuildObject): fileno = getattr(sys.stdout, "fileno", lambda: None)() except io.UnsupportedOperation: fileno = None - if fileno and os.isatty(fileno) and not getattr(self, "NO_AUTO_LOG", False): + if fileno and os.isatty(fileno) and not no_auto_log: self._ensure_state_subdir_exists(".") logfile = self._get_state_filename("last_log.json") try: diff --git a/python/mozbuild/mozbuild/mach_commands.py b/python/mozbuild/mozbuild/mach_commands.py index 00737e8b2c7f..22927c429674 100644 --- a/python/mozbuild/mozbuild/mach_commands.py +++ b/python/mozbuild/mozbuild/mach_commands.py @@ -216,7 +216,6 @@ def doctor(command_context, fix=False, verbose=False): ) -NO_AUTO_LOG = True CLOBBER_CHOICES = {"objdir", "python", "gradle"} @@ -224,6 +223,7 @@ CLOBBER_CHOICES = {"objdir", "python", "gradle"} "clobber", category="build", description="Clobber the tree (delete the object directory).", + no_auto_log=True, ) @CommandArgument( "what", @@ -332,10 +332,9 @@ def clobber(command_context, what, full=False): return ret -NO_AUTO_LOG = True - - -@Command("show-log", category="post-build", description="Display mach logs") +@Command( + "show-log", category="post-build", description="Display mach logs", no_auto_log=True +) @CommandArgument( "log_file", nargs="?",