Bug 1195748 - Fix mach auto-logging on Windows. r?gps draft
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 27 Jul 2016 13:42:18 +0900
changeset 393168 a838a1b003837c62b40658678236ac82f84dd671
parent 393157 d2015878e3eaf4afb608bdd02f71efd8efc394db
child 393176 e6f3ce2d94c5ca05870296340105244ae715ebd8
child 393188 1e6abacbb930d6ad1a8556ccaa83fbcbfac39583
push id24237
push userbmo:mh+mozilla@glandium.org
push dateWed, 27 Jul 2016 05:25:58 +0000
reviewersgps
bugs1195748
milestone50.0a1
Bug 1195748 - Fix mach auto-logging on Windows. r?gps We were relying on the log manager's terminal to know whether we're running on a terminal to turn on auto-logging, but the log manager's terminal is always None on Windows because blessings imports curses, which doesn't work on Windows. So instead, just use a plain os.isatty() call. The same problem also applies to the show-log command to trigger the pager (less). At the same time, fix the environment setting for LESS, as on Windows, unicode literals are not allowed in the environment.
python/mozbuild/mozbuild/base.py
python/mozbuild/mozbuild/mach_commands.py
--- a/python/mozbuild/mozbuild/base.py
+++ b/python/mozbuild/mozbuild/base.py
@@ -750,17 +750,17 @@ class MachCommandBase(MozbuildObject):
                 for line in e.output:
                     print(line)
 
             sys.exit(1)
 
         # Always keep a log of the last command, but don't do that for mach
         # invokations from scripts (especially not the ones done by the build
         # system itself).
-        if (self.log_manager and self.log_manager.terminal and
+        if (os.isatty(sys.stdout.fileno()) and
                 not getattr(self, 'NO_AUTO_LOG', False)):
             self._ensure_state_subdir_exists('.')
             logfile = self._get_state_filename('last_log.json')
             try:
                 fd = open(logfile, "wb")
                 self.log_manager.add_json_handler(fd)
             except Exception as e:
                 self.log(logging.WARNING, 'mach', {'error': e},
--- a/python/mozbuild/mozbuild/mach_commands.py
+++ b/python/mozbuild/mozbuild/mach_commands.py
@@ -667,22 +667,22 @@ class Logs(MachCommandBase):
     @CommandArgument('log_file', nargs='?', type=argparse.FileType('rb'),
         help='Filename to read log data from. Defaults to the log of the last '
              'mach command.')
     def show_log(self, log_file=None):
         if not log_file:
             path = self._get_state_filename('last_log.json')
             log_file = open(path, 'rb')
 
-        if self.log_manager.terminal:
+        if os.isatty(sys.stdout.fileno()):
             env = dict(os.environ)
             if 'LESS' not in env:
                 # Sensible default flags if none have been set in the user
                 # environment.
-                env['LESS'] = 'FRX'
+                env[b'LESS'] = b'FRX'
             less = subprocess.Popen(['less'], stdin=subprocess.PIPE, env=env)
             # Various objects already have a reference to sys.stdout, so we
             # can't just change it, we need to change the file descriptor under
             # it to redirect to less's input.
             # First keep a copy of the sys.stdout file descriptor.
             output_fd = os.dup(sys.stdout.fileno())
             os.dup2(less.stdin.fileno(), sys.stdout.fileno())