Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright (C) 2017 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | import argparse |
| 17 | import os |
| 18 | import shutil |
| 19 | import sys |
| 20 | |
| 21 | |
| 22 | def Main(): |
| 23 | parser = argparse.ArgumentParser() |
| 24 | parser.add_argument('--verbose', '-v', action='store_true') |
| 25 | parser.add_argument('--pid', help='(optional) save pid into given file') |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 26 | args = parser.parse_args() |
| 27 | |
| 28 | root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
Primiano Tucci | e7ca7c6 | 2018-04-07 08:28:03 +0200 | [diff] [blame] | 29 | |
| 30 | if sys.platform.startswith('linux'): |
| 31 | emulator_root = os.path.join( |
| 32 | root_dir, 'buildtools', 'emulator', 'linux-x86_64') |
| 33 | emulator_path = os.path.join(emulator_root, 'qemu', 'linux-x86_64') |
| 34 | else: |
| 35 | emulator_root = os.path.join( |
| 36 | root_dir, 'buildtools', 'emulator', 'darwin-x86_64') |
| 37 | emulator_path = os.path.join(emulator_root, 'qemu', 'darwin-x86_64') |
| 38 | |
Lalit Maganti | 367fcd5 | 2018-02-05 16:06:13 +0000 | [diff] [blame] | 39 | aosp_path = os.path.join(root_dir, 'buildtools', 'aosp-arm') |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 40 | |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 41 | env = { |
| 42 | # Travis CI doesn't set this and causes the emulator to fallback in |
| 43 | # 32-bit mode with a "Cannot decide host bitness because $SHELL" error. |
| 44 | 'SHELL': '/bin/bash', |
Lalit Maganti | 367fcd5 | 2018-02-05 16:06:13 +0000 | [diff] [blame] | 45 | 'LD_LIBRARY_PATH': os.path.join(emulator_root, 'lib64', 'qt', 'lib'), |
Primiano Tucci | e7ca7c6 | 2018-04-07 08:28:03 +0200 | [diff] [blame] | 46 | 'DYLD_LIBRARY_PATH': os.path.join(emulator_root, 'lib64', 'qt', 'lib'), |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 47 | } |
Lalit Maganti | 367fcd5 | 2018-02-05 16:06:13 +0000 | [diff] [blame] | 48 | emulator_bin = os.path.join(emulator_path, 'qemu-system-armel') |
| 49 | emulator_args = ['-no-window', '-no-snapshot', '-gpu', 'off', '-no-accel', |
| 50 | '-sysdir', aosp_path, |
| 51 | '-system', os.path.join(aosp_path, 'system-qemu.img'), |
| 52 | '-kernel', os.path.join(aosp_path, 'kernel-ranchu'), |
| 53 | '-ramdisk', os.path.join(aosp_path, 'ramdisk.img'), |
| 54 | '-vendor', os.path.join(aosp_path, 'vendor-qemu.img'), |
| 55 | '-data', os.path.join(aosp_path, 'userdata-qemu.img')] |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 56 | print '\n'.join('='.join(x) for x in env.items()) |
| 57 | print ' '.join([emulator_bin] + emulator_args) |
| 58 | if args.pid: |
| 59 | with open(args.pid, 'w') as f: |
| 60 | f.write(str(os.getpid())) |
| 61 | os.execve(emulator_bin, [emulator_bin] + emulator_args, env) |
| 62 | |
| 63 | |
| 64 | if __name__ == '__main__': |
| 65 | sys.exit(Main()) |