Chromium Code Reviews| Index: build/android/emulator.py |
| diff --git a/build/android/emulator.py b/build/android/emulator.py |
| index bf5dc083ea24bb2a0e5132d8e20c89be2beee5dd..a122f33b3181706b87bad54220b2b570c9c7846d 100755 |
| --- a/build/android/emulator.py |
| +++ b/build/android/emulator.py |
| @@ -113,10 +113,11 @@ class Emulator(object): |
| # Time to wait for a "wait for boot complete" (property set on device). |
| _WAITFORBOOT_TIMEOUT = 300 |
| - def __init__(self, fast_and_loose=False): |
| + def __init__(self, avd=None, fast_and_loose=False): |
|
bulach
2012/07/16 11:39:13
I think there's only one caller for this. please,
Wei James(wistoch)
2012/07/16 13:04:38
fixed. thanks
|
| """Init an Emulator. |
| Args: |
| + avd: AVD name to launch the emulator. |
| fast_and_loose: Loosen up the rules for reliable running for speed. |
| Intended for quick testing or re-testing. |
| @@ -128,15 +129,59 @@ class Emulator(object): |
| 'emulator.') |
| raise |
| self.emulator = os.path.join(android_sdk_root, 'tools', 'emulator') |
| + self.android = os.path.join(android_sdk_root, 'tools', 'android') |
| self.popen = None |
| self.device = None |
| + self.default_avd = True |
| self.fast_and_loose = fast_and_loose |
| + self.abi = 'armeabi-v7a' |
| + self.avd = 'avd_armeabi' |
| + if 'x86' in os.environ.get('TARGET_PRODUCT', ''): |
| + self.abi = 'x86' |
| + self.avd = 'avd_x86' |
| + if avd != None: |
|
bulach
2012/07/16 11:39:13
nit: no need to compare, just "if avd:" should be
Wei James(wistoch)
2012/07/16 13:04:38
fixed. thanks
|
| + self.default_avd = False |
| + self.avd = self.CreateAVD(avd) |
| def _DeviceName(self): |
| """Return our device name.""" |
| port = _GetAvailablePort() |
| return ('emulator-%d' % port, port) |
| + def CreateAVD(self, avd): |
|
bulach
2012/07/16 11:39:13
nit: add a _ prefix to indicate this is not public
Wei James(wistoch)
2012/07/16 13:04:38
fixed. thanks
|
| + avd_command = [ |
| + self.android, |
| + '--silent', |
| + 'create', 'avd', |
| + '--name', avd, |
| + '--abi', self.abi, |
| + '--target', 'android-15', |
| + '-c', '64M', |
| + '--force', |
| + ] |
| + popen = subprocess.Popen(args=avd_command, |
|
bulach
2012/07/16 11:39:13
nit: rather than popen, maybe name this as avd_pro
Wei James(wistoch)
2012/07/16 13:04:38
fixed. thanks
|
| + stdin=subprocess.PIPE, |
| + stdout=subprocess.PIPE, |
| + stderr=subprocess.STDOUT) |
|
bulach
2012/07/16 11:39:13
nit: indent 163-165 with the ( from 162
Wei James(wistoch)
2012/07/16 13:04:38
fixed. thanks
|
| + popen.stdin.write('no\n') |
| + popen.wait() |
| + logging.info('Create AVD command: %s', ' '.join(avd_command)) |
| + self.avd = avd |
| + return self.avd |
| + |
| + def DeleteAVD(self): |
|
bulach
2012/07/16 11:39:13
nit: _ prefix
Wei James(wistoch)
2012/07/16 13:04:38
fixed. thanks
|
| + avd_command = [ |
| + self.android, |
| + '--silent', |
| + 'delete', |
| + 'avd', |
| + '--name', self.avd, |
| + ] |
| + popen = subprocess.Popen(args=avd_command, |
|
bulach
2012/07/16 11:39:13
nit: avd_process?
Wei James(wistoch)
2012/07/16 13:04:38
fixed. thanks
|
| + stdout=subprocess.PIPE, |
| + stderr=subprocess.STDOUT) |
| + logging.info('Delete AVD command: %s', ' '.join(avd_command)) |
| + |
| def Launch(self, kill_all_emulators): |
| """Launches the emulator asynchronously. Call ConfirmLaunch() to ensure the |
| emulator is ready for use. |
| @@ -148,9 +193,6 @@ class Emulator(object): |
| if not self.fast_and_loose: |
| self._AggressiveImageCleanup() |
| (self.device, port) = self._DeviceName() |
| - abi = 'armeabi' |
| - if 'x86' in os.environ.get('TARGET_PRODUCT', ''): |
| - abi = 'x86' |
| emulator_command = [ |
| self.emulator, |
| # Speed up emulator launch by 40%. Really. |
| @@ -159,7 +201,7 @@ class Emulator(object): |
| # That's not enough for 8 unit test bundles and their data. |
| '-partition-size', '512', |
| # Use a familiar name and port. |
| - '-avd', 'avd_' + abi, |
| + '-avd', self.avd, |
| '-port', str(port)] |
| if not self.fast_and_loose: |
| emulator_command.extend([ |
| @@ -228,6 +270,8 @@ class Emulator(object): |
| def Shutdown(self): |
| """Shuts down the process started by launch.""" |
| + if not self.default_avd: |
| + self.DeleteAVD() |
| if self.popen: |
| self.popen.poll() |
| if self.popen.returncode == None: |
| @@ -247,7 +291,7 @@ class Emulator(object): |
| signal.signal(sig, self._ShutdownOnSignal) |
| def main(argv): |
| - Emulator(True).Launch(True) |
| + Emulator(None, True).Launch(True) |
| if __name__ == '__main__': |