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

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

Issue 15706008: A working version of dart on Android. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Finished CL - ready for review. Created 7 years, 6 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
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 return False 52 return False
53 if not options.output_bin: 53 if not options.output_bin:
54 sys.stderr.write('--output_bin not specified\n') 54 sys.stderr.write('--output_bin not specified\n')
55 return False 55 return False
56 if options.abi and not options.target_os == 'android': 56 if options.abi and not options.target_os == 'android':
57 sys.stderr.write('--abi requires --target_os android\n') 57 sys.stderr.write('--abi requires --target_os android\n')
58 return False 58 return False
59 return True 59 return True
60 60
61 61
62 def RunAdb(device, command):
Søren Gjesse 2013/05/29 09:20:42 Nice!
63 """Run a raw adb command."""
64 return utils.RunCommand(["adb", "-s", device] + command)
65
66
67 def RunAdbShell(device, command):
68 RunAdb(device, ['shell'] + command)
69
70
71 def RunOnAndroid(options):
72 outputBin = options.output_bin
73
74 android_workspace = os.getenv("ANDROID_DART", "/data/local/dart")
75 android_outputBin = join(android_workspace, basename(outputBin))
76
77 executable = options.executable
78 android_executable = join(android_workspace, basename(executable))
79
80 filesToPush = [] # (src, dest)
81 filesToPull = [] # (src, dest)
82
83 # Setup arguments to the snapshot generator binary.
84 script_args = [android_executable]
85
86 # First setup the snapshot output filename.
87 filesToPull.append((android_outputBin, outputBin))
88 script_args.append(''.join([ "--snapshot=", android_outputBin]))
89
90 # We don't know what source files are needed to fully satisfy a dart script,
91 # so we can't support the general case of url mapping or script inclusion.
92 if options.url_mapping:
93 raise Exception("--url_mapping is not supported when building for Android")
94
95 if options.script:
96 raise Exception("--script is not supported when building for Android")
97
98 filesToPush.append((executable, android_executable))
99
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 command = ["tools/android_finder.py", "--bootstrap", "--abi", abi]
104 if VERBOSE:
105 command += ['--verbose']
106 device = utils.RunCommand(command, errStream=sys.stderr)
107
108 if device == None:
109 raise Exception("Could not find Android device for abi %s" % abi)
110
111 device = device.strip()
112
113 if VERBOSE:
114 sys.write.stderr('Using Android device %s for abi %s' % (device, abi))
115
116 RunAdbShell(device, ["mkdir", android_workspace])
117
118 try:
119 if VERBOSE:
120 sys.write.stderr('pushing files to %s' % device)
121 for src, dest in filesToPush:
122 RunAdb(device, ["push", src, dest])
123 if VERBOSE:
124 sys.write.stderr('running snapshot generator')
125 RunAdbShell(device, script_args)
126 if VERBOSE:
127 sys.write.stderr('retrieving snapshot')
128 for src, dest in filesToPull:
129 RunAdb(device, ["pull", src, dest])
130 finally:
131 if VERBOSE:
132 sys.write.stderr('cleaning intermediate files')
133 for src, dest in filesToPush:
134 RunAdbShell(device, ["rm", dest])
135 for src, dest in filesToPull:
136 RunAdbShell(device, ["rm", src])
137
138
139 def Main(): 62 def Main():
140 # Parse options. 63 # Parse options.
141 parser = BuildOptions() 64 parser = BuildOptions()
142 (options, args) = parser.parse_args() 65 (options, args) = parser.parse_args()
143 if not ProcessOptions(options): 66 if not ProcessOptions(options):
144 parser.print_help() 67 parser.print_help()
145 return 1 68 return 1
146 69
147 # If there are additional arguments, report error and exit. 70 # If there are additional arguments, report error and exit.
148 if args: 71 if args:
149 parser.print_help() 72 parser.print_help()
150 return 1 73 return 1
151 74
152 # Setup arguments to the snapshot generator binary. 75 # Setup arguments to the snapshot generator binary.
153 script_args = ["--error_on_malformed_type"] 76 script_args = ["--error_on_malformed_type"]
154 77
155 # First setup the snapshot output filename. 78 # First setup the snapshot output filename.
156 script_args.append(''.join([ "--snapshot=", options.output_bin ])) 79 script_args.append(''.join([ "--snapshot=", options.output_bin ]))
157 80
158 # Next setup all url mapping options specified. 81 # Next setup all url mapping options specified.
159 for url_arg in options.url_mapping: 82 for url_arg in options.url_mapping:
160 url_mapping_argument = ''.join(["--url_mapping=", url_arg ]) 83 url_mapping_argument = ''.join(["--url_mapping=", url_arg ])
161 script_args.append(url_mapping_argument) 84 script_args.append(url_mapping_argument)
162 85
163 # Finally append the script name if one is specified. 86 # Finally append the script name if one is specified.
164 if options.script: 87 if options.script:
165 script_args.append(options.script) 88 script_args.append(options.script)
166 89
167 # Construct command line to execute the snapshot generator binary and invoke. 90 # Construct command line to execute the snapshot generator binary and invoke.
168 if options.target_os == 'android': 91 command = [ options.executable ] + script_args
169 RunOnAndroid(options) 92 try:
170 else: 93 utils.RunCommand(command, outStream=sys.stderr, errStream=sys.stderr,
171 command = [ options.executable ] + script_args 94 verbose=options.verbose, printErrorInfo=True)
172 try: 95 except Exception as e:
173 utils.RunCommand(command, outStream=sys.stderr, errStream=sys.stderr, 96 return -1
174 verbose=options.verbose, printErrorInfo=True)
175 except Exception as e:
176 return -1
177 97
178 return 0 98 return 0
179 99
180 100
181 if __name__ == '__main__': 101 if __name__ == '__main__':
182 sys.exit(Main()) 102 sys.exit(Main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698