From 115f77927e8a342c6a015f54b2037c8db4529607 Mon Sep 17 00:00:00 2001 From: Armen Zambrano Gasparnian Date: Mon, 11 Aug 2014 08:59:56 -0400 Subject: [PATCH] Bug 1046087 - Normalize line endings on mozprocess for Adb Windows. r=wlach --- .../mozbase/mozprocess/mozprocess/processhandler.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/testing/mozbase/mozprocess/mozprocess/processhandler.py b/testing/mozbase/mozprocess/mozprocess/processhandler.py index 28125d3ee3a6..3777e4e7bb99 100644 --- a/testing/mozbase/mozprocess/mozprocess/processhandler.py +++ b/testing/mozbase/mozprocess/mozprocess/processhandler.py @@ -3,6 +3,7 @@ # You can obtain one at http://mozilla.org/MPL/2.0/. import os +import re import select import signal import subprocess @@ -838,10 +839,17 @@ falling back to not using job objects for managing child processes""" PeekNamedPipe = ctypes.windll.kernel32.PeekNamedPipe GetLastError = ctypes.windll.kernel32.GetLastError + @staticmethod + def _normalize_newline(line): + # adb on windows returns \r\r\n at the end of each line, to get around + # this normalize all newlines to have a unix-style '\n' + # http://src.chromium.org/viewvc/chrome/trunk/src/build/android/pylib/android_commands.py#l1944 + return re.sub(r'\r+\n?$', '\n', line) + def _readWithTimeout(self, f, timeout): if timeout is None: # shortcut to allow callers to pass in "None" for no timeout. - return (f.readline(), False) + return (self._normalize_newline(f.readline()), False) x = msvcrt.get_osfhandle(f.fileno()) l = ctypes.c_long() done = time.time() + timeout @@ -855,7 +863,7 @@ falling back to not using job objects for managing child processes""" if l.value > 0: # we're assuming that the output is line-buffered, # which is not unreasonable - return (f.readline(), False) + return (self._normalize_newline(f.readline()), False) time.sleep(0.01) return ('', True)