Bug 1195748 - Fix mach auto-logging on Windows. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 27 Jul 2016 13:42:18 +0900
changeset 346901 ace86bc6c5b16d3c46b2d348a018c0762ffdf3d0
parent 346900 508cfc7bcace32ecbd09f68fcb5879dab8ca30bb
child 346902 a182c19604154fe9319be404ec48020c394bb894
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1195748
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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())