• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
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
16import argparse
17import os
18import sys
19
20
21def Main():
22  parser = argparse.ArgumentParser()
23  parser.add_argument('--verbose', '-v', action='store_true')
24  parser.add_argument('--pid', help='(optional) save pid into given file')
25  args = parser.parse_args()
26
27  root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
28
29  if sys.platform.startswith('linux'):
30    emulator_root = os.path.join(root_dir, 'buildtools', 'emulator',
31                                 'linux-x86_64')
32    emulator_path = os.path.join(emulator_root, 'qemu', 'linux-x86_64')
33  else:
34    emulator_root = os.path.join(root_dir, 'buildtools', 'emulator',
35                                 'darwin-x86_64')
36    emulator_path = os.path.join(emulator_root, 'qemu', 'darwin-x86_64')
37
38  aosp_path = os.path.join(root_dir, 'buildtools', 'aosp-arm')
39
40  env = {
41      # The CI env doesn't set this and causes the emulator to fallback in
42      # 32-bit mode with a "Cannot decide host bitness because $SHELL" error.
43      'SHELL': '/bin/bash',
44      'LD_LIBRARY_PATH': os.path.join(emulator_root, 'lib64', 'qt', 'lib'),
45      'DYLD_LIBRARY_PATH': os.path.join(emulator_root, 'lib64', 'qt', 'lib'),
46  }
47  emulator_bin = os.path.join(emulator_path, 'qemu-system-armel')
48  emulator_args = [
49      '-no-window', '-no-snapshot', '-gpu', 'off', '-no-accel', '-sysdir',
50      aosp_path, '-system',
51      os.path.join(aosp_path, 'system-qemu.img'), '-kernel',
52      os.path.join(aosp_path, 'kernel-ranchu'), '-ramdisk',
53      os.path.join(aosp_path, 'ramdisk.img'), '-vendor',
54      os.path.join(aosp_path, 'vendor-qemu.img'), '-data',
55      os.path.join(aosp_path, 'userdata-qemu.img')
56  ]
57  print('\n'.join('='.join(x) for x in env.items()))
58  print(' '.join([emulator_bin] + emulator_args))
59  if args.pid:
60    with open(args.pid, 'w') as f:
61      f.write(str(os.getpid()))
62  os.execve(emulator_bin, [emulator_bin] + emulator_args, env)
63
64
65if __name__ == '__main__':
66  sys.exit(Main())
67