Bug 755856 - look for adb in path first for mozdevice emulator automation, r=jgriffin
authorMalini Das <mdas@mozilla.com>
Thu, 23 Aug 2012 15:46:48 -0400
changeset 105250 0a7b2834337b53afb19e895aaa4de56d7a0edeb7
parent 105249 9fbe008c291f3e983e5a3618c3b9a4f6f6dd2558
child 105251 e53c5799835032cc436209da3194d3b43474d524
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersjgriffin
bugs755856
milestone17.0a1
Bug 755856 - look for adb in path first for mozdevice emulator automation, r=jgriffin
build/mobile/b2gemulator.py
build/mobile/emulator.py
--- a/build/mobile/b2gemulator.py
+++ b/build/mobile/b2gemulator.py
@@ -24,20 +24,27 @@ class B2GEmulator(Emulator):
 
     def _check_file(self, filePath):
         if not os.path.exists(filePath):
             raise Exception(('File not found: %s; did you pass the B2G home '
                              'directory as the homedir parameter, or set '
                              'B2G_HOME correctly?') % filePath)
 
     def _check_for_adb(self, host_dir):
-        self.adb = os.path.join(self.homedir, 'out', 'host', host_dir, 'bin', 'adb')
-        if not os.path.exists(self.adb):
-            self.adb = os.path.join(self.homedir, 'bin/adb')
-        super(B2GEmulator, self)._check_for_adb()
+        if self._default_adb() == 0:
+            return
+        adb_paths = [os.path.join(self.homedir,'glue','gonk','out','host',
+                      host_dir ,'bin','adb'),os.path.join(self.homedir, 'out',
+                      'host', host_dir,'bin','adb'),os.path.join(self.homedir,
+                      'bin','adb')]
+        for option in adb_paths:
+            if os.path.exists(option):
+                self.adb = option
+                return
+        raise Exception('adb not found!')
 
     def _locate_files(self):
         if self.homedir is None:
             self.homedir = os.getenv('B2G_HOME')
         if self.homedir is None:
             raise Exception('Must define B2G_HOME or pass the homedir parameter')
         self._check_file(self.homedir)
 
--- a/build/mobile/emulator.py
+++ b/build/mobile/emulator.py
@@ -82,27 +82,29 @@ class Emulator(object):
 
     @property
     def is_running(self):
         if self._emulator_launched:
             return self.proc is not None and self.proc.poll() is None
         else:
             return self.port is not None
 
+    def _default_adb(self):
+        adb = subprocess.Popen(['which', 'adb'],
+                               stdout=subprocess.PIPE,
+                               stderr=subprocess.STDOUT)
+        retcode = adb.wait()
+        if retcode == 0:
+            self.adb = adb.stdout.read().strip() # remove trailing newline
+        return retcode
+
     def _check_for_adb(self):
         if not os.path.exists(self.adb):
-            adb = subprocess.Popen(['which', 'adb'],
-                                   stdout=subprocess.PIPE,
-                                   stderr=subprocess.STDOUT)
-            retcode = adb.wait()
-            if retcode:
+            if self._default_adb() != 0:
                 raise Exception('adb not found!')
-            out = adb.stdout.read().strip()
-            if len(out) and out.find('/') > -1:
-                self.adb = out
 
     def _run_adb(self, args):
         args.insert(0, self.adb)
         adb = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
         retcode = adb.wait()
         if retcode:
             raise Exception('adb terminated with exit code %d: %s'
             % (retcode, adb.stdout.read()))