Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(639)

Side by Side Diff: runtime/tools/create_snapshot_bin.py

Issue 10823209: Add support for building the Dart VM for Android OS. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: build.py learned --os all option to build for both host and android. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
4 # for details. All rights reserved. Use of this source code is governed by a 4 # for details. All rights reserved. Use of this source code is governed by a
5 # BSD-style license that can be found in the LICENSE file. 5 # BSD-style license that can be found in the LICENSE file.
6 6
7 """Script to create snapshot bin file.""" 7 """Script to create snapshot bin file."""
8 8
9 import getopt 9 import getopt
10 import optparse 10 import optparse
11 import os 11 import os
12 from os.path import abspath, basename, dirname, join 12 from os.path import basename, join
13 import string
14 import subprocess
15 import sys 13 import sys
16 import tempfile
17 import utils 14 import utils
18 15
19 16
20 HOST_OS = utils.GuessOS() 17 HOST_OS = utils.GuessOS()
21 HOST_CPUS = utils.GuessCpus() 18 HOST_CPUS = utils.GuessCpus()
22 19 DEBUG = False
20 VERBOSE = False
23 21
24 def BuildOptions(): 22 def BuildOptions():
25 result = optparse.OptionParser() 23 result = optparse.OptionParser()
26 result.add_option("--executable", 24 result.add_option("--executable",
27 action="store", type="string", 25 action="store", type="string",
28 help="path to snapshot generator executable") 26 help="path to snapshot generator executable")
29 result.add_option("--output_bin", 27 result.add_option("--output_bin",
30 action="store", type="string", 28 action="store", type="string",
31 help="output file name into which snapshot in binary form is generated") 29 help="output file name into which snapshot in binary form is generated")
32 result.add_option("--script", 30 result.add_option("--script",
33 action="store", type="string", 31 action="store", type="string",
34 help="Dart script for which snapshot is to be generated") 32 help="Dart script for which snapshot is to be generated")
35 result.add_option("--url_mapping", 33 result.add_option("--url_mapping",
36 default=[], 34 default=[],
37 action="append", 35 action="append",
38 help="mapping from url to file name, used when generating snapshots") 36 help="mapping from url to file name, used when generating snapshots")
39 result.add_option("-v", "--verbose", 37 result.add_option("-v", "--verbose",
40 help='Verbose output.', 38 help='Verbose output.',
41 default=False, action="store_true") 39 default=False, action="store_true")
42 result.add_option("--target_os", 40 result.add_option("--target_os",
43 action="store", type="string", 41 action="store", type="string",
44 help="Which os to run the executable on") 42 help="Which os to run the executable on. Current choice is android")
43 result.add_option("--abi",
44 action="store", type="string",
45 help="Desired ABI for android target OS. armeabi-v7a or x86")
45 return result 46 return result
46 47
47 48
48 def ProcessOptions(options): 49 def ProcessOptions(options):
49 if not options.executable: 50 if not options.executable:
50 sys.stderr.write('--executable not specified\n') 51 sys.stderr.write('--executable not specified\n')
51 return False 52 return False
52 if not options.output_bin: 53 if not options.output_bin:
53 sys.stderr.write('--output_bin not specified\n') 54 sys.stderr.write('--output_bin not specified\n')
54 return False 55 return False
56 if options.abi and not options.target_os == 'android':
57 sys.stderr.write('--abi requires --target_os android\n')
58 return False
55 return True 59 return True
56 60
57 61
58 def RunHost(command): 62 def RunAdb(device, command):
59 print "command %s" % command 63 """Run a raw adb command."""
60 pipe = subprocess.Popen(args=command, 64 return utils.RunCommand(["adb", "-s", device] + command)
61 shell=True,
62 stdout=subprocess.PIPE,
63 stderr=subprocess.PIPE)
64 out, error = pipe.communicate()
65 if (pipe.returncode != 0):
66 print out, error
67 print "command failed"
68 print "(Command was: '", ' '.join(command), "')"
69 raise Exception("Failed")
70 65
71 66
72 def RunTarget(command): 67 def RunAdbShell(device, command):
73 RunHost("adb shell %s" % command) 68 RunAdb(device, ['shell'] + command)
74 69
75 70
76 def RunOnAndroid(options): 71 def RunOnAndroid(options):
77 outputBin = options.output_bin 72 outputBin = options.output_bin
78 73
79 android_workspace = os.getenv("ANDROID_DART", "/data/local/dart") 74 android_workspace = os.getenv("ANDROID_DART", "/data/local/dart")
80 android_outputBin = join(android_workspace, basename(outputBin)) 75 android_outputBin = join(android_workspace, basename(outputBin))
81 76
82 executable = options.executable 77 executable = options.executable
83 android_executable = join(android_workspace, basename(executable)) 78 android_executable = join(android_workspace, basename(executable))
(...skipping 11 matching lines...) Expand all
95 # We don't know what source files are needed to fully satisfy a dart script, 90 # We don't know what source files are needed to fully satisfy a dart script,
96 # so we can't support the general case of url mapping or script inclusion. 91 # so we can't support the general case of url mapping or script inclusion.
97 if options.url_mapping: 92 if options.url_mapping:
98 raise Exception("--url_mapping is not supported when building for Android") 93 raise Exception("--url_mapping is not supported when building for Android")
99 94
100 if options.script: 95 if options.script:
101 raise Exception("--script is not supported when building for Android") 96 raise Exception("--script is not supported when building for Android")
102 97
103 filesToPush.append((executable, android_executable)) 98 filesToPush.append((executable, android_executable))
104 99
105 command = ' '.join(script_args) 100 abi = options.abi or 'x86'
101 # We know we're run in the runtime directory, and we know the relative path
102 # to the tools we want to execute:
103 device = utils.RunCommand(
104 ["tools/android_finder.py", "--bootstrap", "--abi", abi, '--verbose'],
105 errStream=sys.stderr)
106 106
107 RunHost("adb shell mkdir %s" % android_workspace) 107 if device == None:
108 raise Exception("Could not find Android device for abi %s" % abi)
109
110 device = device.strip()
111
112 RunAdbShell(device, ["mkdir", android_workspace])
113
108 try: 114 try:
109 for src, dest in filesToPush: 115 for src, dest in filesToPush:
110 RunHost("adb push '%s' '%s'" % (src, dest)) 116 RunAdb(device, ["push", src, dest])
111 RunTarget(command) 117 RunAdbShell(device, script_args)
112 for src, dest in filesToPull: 118 for src, dest in filesToPull:
113 RunHost("adb pull '%s' '%s'" % (src, dest)) 119 RunAdb(device, ["pull", src, dest])
114 finally: 120 finally:
115 for src, dest in filesToPush: 121 for src, dest in filesToPush:
116 RunHost("adb shell rm '%s'" % dest) 122 RunAdbShell(device, ["rm", dest])
117 for src, dest in filesToPull: 123 for src, dest in filesToPull:
118 RunHost("adb shell rm '%s'" % src) 124 RunAdbShell(device, ["rm", src])
119 125
120 126
121 def Main(): 127 def Main():
122 # Parse options. 128 # Parse options.
123 parser = BuildOptions() 129 parser = BuildOptions()
124 (options, args) = parser.parse_args() 130 (options, args) = parser.parse_args()
125 if not ProcessOptions(options): 131 if not ProcessOptions(options):
126 parser.print_help() 132 parser.print_help()
127 return 1 133 return 1
128 134
(...skipping 11 matching lines...) Expand all
140 # Next setup all url mapping options specified. 146 # Next setup all url mapping options specified.
141 for url_arg in options.url_mapping: 147 for url_arg in options.url_mapping:
142 url_mapping_argument = ''.join(["--url_mapping=", url_arg ]) 148 url_mapping_argument = ''.join(["--url_mapping=", url_arg ])
143 script_args.append(url_mapping_argument) 149 script_args.append(url_mapping_argument)
144 150
145 # Finally append the script name if one is specified. 151 # Finally append the script name if one is specified.
146 if options.script: 152 if options.script:
147 script_args.append(options.script) 153 script_args.append(options.script)
148 154
149 # Construct command line to execute the snapshot generator binary and invoke. 155 # Construct command line to execute the snapshot generator binary and invoke.
150 command = [ options.executable ] + script_args
151 if options.verbose:
152 print ' '.join(command)
153
154 if options.target_os == 'android': 156 if options.target_os == 'android':
157 RunOnAndroid(options)
158 else:
159 command = [ options.executable ] + script_args
155 try: 160 try:
156 RunOnAndroid(options) 161 utils.RunCommand(command, outStream=sys.stderr, errStream=sys.stderr,
162 verbose=options.verbose, printErrorInfo=True)
157 except Exception as e: 163 except Exception as e:
158 print "Could not run on Android: %s" % e
159 return -1
160 else:
161 pipe = subprocess.Popen(command,
162 stdout=subprocess.PIPE,
163 stderr=subprocess.PIPE)
164 out, error = pipe.communicate()
165 if (pipe.returncode != 0):
166 print out, error
167 print "Snapshot generation failed"
168 print "(Command was: '", ' '.join(command), "')"
169 return -1 164 return -1
170 165
171 return 0 166 return 0
172 167
173 168
174 if __name__ == '__main__': 169 if __name__ == '__main__':
175 sys.exit(Main()) 170 sys.exit(Main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698