Bug 543825 remove __import__ from automation.py r=ted
☠☠ backed out by 3dadc7cacb96 ☠ ☠
authorJoel Maher <jmaher@mozilla.com>
Sat, 13 Mar 2010 11:20:27 -0800
changeset 39399 31b7d1785eb23d24f33c578c7a20c2e4704469e7
parent 39398 640c7807d972a7363e18bcb0fd38c1b29f6fb410
child 39400 3dadc7cacb96aa4005fe60b0ee54971519ddcb9d
push id12172
push userctalbert@mozilla.com
push dateSat, 13 Mar 2010 19:23:37 +0000
treeherdermozilla-central@31b7d1785eb2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs543825
milestone1.9.3a3pre
Bug 543825 remove __import__ from automation.py r=ted
build/automation.py.in
--- a/build/automation.py.in
+++ b/build/automation.py.in
@@ -69,16 +69,23 @@ import tempfile
 #expand _PERL = __PERL__
 
 #expand _DEFAULT_APP = "./" + __BROWSER_PATH__
 #expand _CERTS_SRC_DIR = __CERTS_SRC_DIR__
 #expand _IS_TEST_BUILD = __IS_TEST_BUILD__
 #expand _IS_DEBUG_BUILD = __IS_DEBUG_BUILD__
 #expand _CRASHREPORTER = __CRASHREPORTER__ == 1
 
+
+if _IS_WIN32:
+  import ctypes, ctypes.wintypes, time, msvcrt
+else:
+  import errno
+
+
 #################
 # PROFILE SETUP #
 #################
 
 class SyntaxError(Exception):
   "Signifies a syntax error on a particular line in server-locations.txt."
 
   def __init__(self, lineno, msg = None):
@@ -461,17 +468,17 @@ user_pref("camino.use_system_proxy_setti
     return 0
 
   def environment(self, env = None, xrePath = None, crashreporter = True):
     if xrePath == None:
       xrePath = self.DIST_BIN
     if env == None:
       env = dict(os.environ)
 
-    ldLibraryPath = os.path.abspath(os.path.join(self.SCRIPT_DIR, xrePath))
+    ldLibraryPath = os.path.abspath(os.path.join(SCRIPT_DIR, xrePath))
     if self.UNIXISH or self.IS_MAC:
       envVar = "LD_LIBRARY_PATH"
       if self.IS_MAC:
         envVar = "DYLD_LIBRARY_PATH"
       else: # unixish
         env['MOZILLA_FIVE_HOME'] = xrePath
       if envVar in env:
         ldLibraryPath = ldLibraryPath + ":" + env[envVar]
@@ -485,74 +492,69 @@ user_pref("camino.use_system_proxy_setti
     else:
       env['MOZ_CRASHREPORTER_DISABLE'] = '1'
 
     env['GNOME_DISABLE_CRASH_DIALOG'] = '1'
     env['XRE_NO_WINDOWS_CRASH_DIALOG'] = '1'
     return env
 
   if IS_WIN32:
-    ctypes = __import__('ctypes')
-    wintypes = __import__('ctypes.wintypes')
-    time = __import__('time')
-    msvcrt = __import__('msvcrt')
     PeekNamedPipe = ctypes.windll.kernel32.PeekNamedPipe
     GetLastError = ctypes.windll.kernel32.GetLastError
 
     def readWithTimeout(self, f, timeout):
       """Try to read a line of output from the file object |f|.
       |f| must be a  pipe, like the |stdout| member of a subprocess.Popen
       object created with stdout=PIPE. If no output
       is received within |timeout| seconds, return a blank line.
       Returns a tuple (line, did_timeout), where |did_timeout| is True
       if the read timed out, and False otherwise."""
       if timeout is None:
         # shortcut to allow callers to pass in "None" for no timeout.
         return (f.readline(), False)
-      x = self.msvcrt.get_osfhandle(f.fileno())
-      l = self.ctypes.c_long()
-      done = self.time.time() + timeout
-      while self.time.time() < done:
-        if self.PeekNamedPipe(x, None, 0, None, self.ctypes.byref(l), None) == 0:
+      x = msvcrt.get_osfhandle(f.fileno())
+      l = ctypes.c_long()
+      done = time.time() + timeout
+      while time.time() < done:
+        if self.PeekNamedPipe(x, None, 0, None, ctypes.byref(l), None) == 0:
           err = self.GetLastError()
           if err == 38 or err == 109: # ERROR_HANDLE_EOF || ERROR_BROKEN_PIPE
             return ('', False)
           else:
             log.error("readWithTimeout got error: %d", err)
         if l.value > 0:
           # we're assuming that the output is line-buffered,
           # which is not unreasonable
           return (f.readline(), False)
-        self.time.sleep(0.01)
+        time.sleep(0.01)
       return ('', True)
 
     def isPidAlive(self, pid):
       STILL_ACTIVE = 259
       PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
-      pHandle = self.ctypes.windll.kernel32.OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, pid)
+      pHandle = ctypes.windll.kernel32.OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, pid)
       if not pHandle:
         return False
       pExitCode = ctypes.wintypes.DWORD()
-      self.ctypes.windll.kernel32.GetExitCodeProcess(pHandle, self.ctypes.byref(pExitCode))
-      self.ctypes.windll.kernel32.CloseHandle(pHandle)
+      ctypes.windll.kernel32.GetExitCodeProcess(pHandle, self.ctypes.byref(pExitCode))
+      ctypes.windll.kernel32.CloseHandle(pHandle)
       if (pExitCode.value == STILL_ACTIVE):
         return True
       else:
         return False
 
     def killPid(self, pid):
       PROCESS_TERMINATE = 0x0001
-      pHandle = self.ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, 0, pid)
+      pHandle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, 0, pid)
       if not pHandle:
         return
-      success = self.ctypes.windll.kernel32.TerminateProcess(pHandle, 1)
-      self.ctypes.windll.kernel32.CloseHandle(pHandle)
+      success = ctypes.windll.kernel32.TerminateProcess(pHandle, 1)
+      ctypes.windll.kernel32.CloseHandle(pHandle)
 
   else:
-    errno = __import__('errno')
 
     def readWithTimeout(self, f, timeout):
       """Try to read a line of output from the file object |f|. If no output
       is received within |timeout| seconds, return a blank line.
       Returns a tuple (line, did_timeout), where |did_timeout| is True
       if the read timed out, and False otherwise."""
       (r, w, e) = select.select([f], [], [], timeout)
       if len(r) == 0:
@@ -570,17 +572,17 @@ user_pref("camino.use_system_proxy_setti
         wpid, wstatus = os.waitpid(pid, os.WNOHANG)
         if wpid == 0:
           return True
 
         return False
       except OSError, err:
         # Catch the errors we might expect from os.kill/os.waitpid, 
         # and re-raise any others
-        if err.errno == self.errno.ESRCH or err.errno == self.errno.ECHILD:
+        if err.errno == errno.ESRCH or err.errno == errno.ECHILD:
           return False
         raise
 
     def killPid(self, pid):
       os.kill(pid, signal.SIGKILL)
 
   def triggerBreakpad(self, proc, utilityPath):
     """Attempt to kill this process in a way that triggers Breakpad crash
@@ -756,17 +758,17 @@ user_pref("camino.use_system_proxy_setti
                  stderr = subprocess.STDOUT)
     self.log.info("INFO | automation.py | Application pid: %d", proc.pid)
 
     status = self.waitForFinish(proc, utilityPath, timeout, maxTime, startTime)
     self.log.info("INFO | automation.py | Application ran for: %s", str(datetime.now() - startTime))
 
     # Do a final check for zombie child processes.
     self.checkForZombies(processLog)
-    self.automationutils.checkForCrashes(os.path.join(profileDir, "minidumps"), symbolsPath)
+    automationutils.checkForCrashes(os.path.join(profileDir, "minidumps"), symbolsPath)
 
     if os.path.exists(processLog):
       os.unlink(processLog)
 
     if self.IS_TEST_BUILD and runSSLTunnel:
       ssltunnelProcess.kill()
 
     return status