OLD | NEW |
---|---|
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", |
(...skipping 15 matching lines...) Expand all Loading... | |
48 def ProcessOptions(options): | 46 def ProcessOptions(options): |
49 if not options.executable: | 47 if not options.executable: |
50 sys.stderr.write('--executable not specified\n') | 48 sys.stderr.write('--executable not specified\n') |
51 return False | 49 return False |
52 if not options.output_bin: | 50 if not options.output_bin: |
53 sys.stderr.write('--output_bin not specified\n') | 51 sys.stderr.write('--output_bin not specified\n') |
54 return False | 52 return False |
55 return True | 53 return True |
56 | 54 |
57 | 55 |
58 def RunHost(command): | 56 def RunAdb(device, command): |
59 print "command %s" % command | 57 """Run a raw adb command.""" |
60 pipe = subprocess.Popen(args=command, | 58 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 | 59 |
71 | 60 |
72 def RunTarget(command): | 61 def RunAdbShell(device, command): |
73 RunHost("adb shell %s" % command) | 62 RunAdb(device, ['shell'] + command) |
74 | 63 |
75 | 64 |
76 def RunOnAndroid(options): | 65 def RunOnAndroid(options): |
77 outputBin = options.output_bin | 66 outputBin = options.output_bin |
78 | 67 |
79 android_workspace = os.getenv("ANDROID_DART", "/data/local/dart") | 68 android_workspace = os.getenv("ANDROID_DART", "/data/local/dart") |
80 android_outputBin = join(android_workspace, basename(outputBin)) | 69 android_outputBin = join(android_workspace, basename(outputBin)) |
81 | 70 |
82 executable = options.executable | 71 executable = options.executable |
83 android_executable = join(android_workspace, basename(executable)) | 72 android_executable = join(android_workspace, basename(executable)) |
(...skipping 11 matching lines...) Expand all Loading... | |
95 # We don't know what source files are needed to fully satisfy a dart script, | 84 # 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. | 85 # so we can't support the general case of url mapping or script inclusion. |
97 if options.url_mapping: | 86 if options.url_mapping: |
98 raise Exception("--url_mapping is not supported when building for Android") | 87 raise Exception("--url_mapping is not supported when building for Android") |
99 | 88 |
100 if options.script: | 89 if options.script: |
101 raise Exception("--script is not supported when building for Android") | 90 raise Exception("--script is not supported when building for Android") |
102 | 91 |
103 filesToPush.append((executable, android_executable)) | 92 filesToPush.append((executable, android_executable)) |
104 | 93 |
105 command = ' '.join(script_args) | 94 abi = 'x86' |
95 # We know we're run in the runtime directory, and we know the relative path | |
96 # to the tools we want to execute: | |
97 # try: | |
Emily Fortuna
2012/08/28 16:49:14
Just remove code instead of commenting out
jackpal
2012/08/28 20:15:20
Done.
| |
98 device = utils.RunCommand( | |
99 ["tools/android_finder.py", "--bootstrap", "--abi", abi, '--verbose'], | |
100 errStream=sys.stderr) | |
101 # except Exception as e: | |
102 # device = None | |
106 | 103 |
107 RunHost("adb shell mkdir %s" % android_workspace) | 104 if device == None: |
105 raise Exception("Could not find Android device for abi %s" % abi) | |
106 | |
107 device = device.strip() | |
108 | |
109 RunAdbShell(device, ["mkdir", android_workspace]) | |
110 | |
108 try: | 111 try: |
109 for src, dest in filesToPush: | 112 for src, dest in filesToPush: |
110 RunHost("adb push '%s' '%s'" % (src, dest)) | 113 RunAdb(device, ["push", src, dest]) |
111 RunTarget(command) | 114 RunAdbShell(device, script_args) |
112 for src, dest in filesToPull: | 115 for src, dest in filesToPull: |
113 RunHost("adb pull '%s' '%s'" % (src, dest)) | 116 RunAdb(device, ["pull", src, dest]) |
114 finally: | 117 finally: |
115 for src, dest in filesToPush: | 118 for src, dest in filesToPush: |
116 RunHost("adb shell rm '%s'" % dest) | 119 RunAdbShell(device, ["rm", dest]) |
117 for src, dest in filesToPull: | 120 for src, dest in filesToPull: |
118 RunHost("adb shell rm '%s'" % src) | 121 RunAdbShell(device, ["rm", src]) |
119 | 122 |
120 | 123 |
121 def Main(): | 124 def Main(): |
122 # Parse options. | 125 # Parse options. |
123 parser = BuildOptions() | 126 parser = BuildOptions() |
124 (options, args) = parser.parse_args() | 127 (options, args) = parser.parse_args() |
125 if not ProcessOptions(options): | 128 if not ProcessOptions(options): |
126 parser.print_help() | 129 parser.print_help() |
127 return 1 | 130 return 1 |
128 | 131 |
(...skipping 11 matching lines...) Expand all Loading... | |
140 # Next setup all url mapping options specified. | 143 # Next setup all url mapping options specified. |
141 for url_arg in options.url_mapping: | 144 for url_arg in options.url_mapping: |
142 url_mapping_argument = ''.join(["--url_mapping=", url_arg ]) | 145 url_mapping_argument = ''.join(["--url_mapping=", url_arg ]) |
143 script_args.append(url_mapping_argument) | 146 script_args.append(url_mapping_argument) |
144 | 147 |
145 # Finally append the script name if one is specified. | 148 # Finally append the script name if one is specified. |
146 if options.script: | 149 if options.script: |
147 script_args.append(options.script) | 150 script_args.append(options.script) |
148 | 151 |
149 # Construct command line to execute the snapshot generator binary and invoke. | 152 # 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': | 153 if options.target_os == 'android': |
154 RunOnAndroid(options) | |
155 else: | |
156 command = [ options.executable ] + script_args | |
155 try: | 157 try: |
156 RunOnAndroid(options) | 158 utils.RunCommand(command, outStream=sys.stderr, errStream=sys.stderr, |
159 verbose=options.verbose, printErrorInfo=True) | |
157 except Exception as e: | 160 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 | 161 return -1 |
170 | 162 |
171 return 0 | 163 return 0 |
172 | 164 |
173 | 165 |
174 if __name__ == '__main__': | 166 if __name__ == '__main__': |
175 sys.exit(Main()) | 167 sys.exit(Main()) |
OLD | NEW |