Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """Command line wrapper to run the frog compiler under the Dart VM""" | 6 """Command line wrapper to run the frog compiler under the Dart VM""" |
| 7 | 7 |
| 8 # TODO(jimhug): This is a temporary hack to enable running on the VM. We need | 8 # TODO(jimhug): This is a temporary hack to enable running on the VM. We need |
| 9 # the ability to get command-line arguments, to return exit codes, and to | 9 # the ability to get command-line arguments, to return exit codes, and to |
| 10 # communicate with spawned processes in the VM for this to go away. | 10 # communicate with spawned processes in the VM for this to go away. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 dart = join(os.pardir, dart) | 51 dart = join(os.pardir, dart) |
| 52 if exists(dart): return dart | 52 if exists(dart): return dart |
| 53 | 53 |
| 54 # Try a debug version | 54 # Try a debug version |
| 55 dart = utils.GetDartRunner('debug', 'ia32', 'vm') | 55 dart = utils.GetDartRunner('debug', 'ia32', 'vm') |
| 56 if exists(dart): return dart | 56 if exists(dart): return dart |
| 57 # Try at the top level | 57 # Try at the top level |
| 58 dart = join(os.pardir, dart) | 58 dart = join(os.pardir, dart) |
| 59 return dart | 59 return dart |
| 60 | 60 |
| 61 def GetD8(): | |
|
ngeoffray
2011/11/04 10:42:21
With frog.py soon to be removed, I don't think it'
| |
| 62 system = utils.GuessOS() | |
| 63 d8 = join(utils.GetBuildRoot(system, 'release', 'ia32'), 'd8') | |
| 64 if exists(d8): return d8 | |
| 65 # Try at the top level | |
| 66 d8 = join(os.pardir, d8) | |
| 67 if exists(d8): return d8 | |
| 68 | |
| 69 # Try a debug version | |
| 70 d8 = join(utils.GetBuildRoot(system, 'debug', 'ia32'), 'd8') | |
| 71 if exists(d8): return d8 | |
| 72 # Try at the top level | |
| 73 d8 = join(os.pardir, d8) | |
| 74 return d8 | |
| 75 | |
| 76 | |
| 77 D8 = GetD8() | |
| 61 | 78 |
| 62 def execute(cmd): | 79 def execute(cmd): |
| 63 """Execute a command in a subprocess. """ | 80 """Execute a command in a subprocess. """ |
| 64 try: | 81 try: |
| 65 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 82 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 66 out, err = pipe.communicate() | 83 out, err = pipe.communicate() |
| 67 if out is not None: sys.stdout.write(out) | 84 if out is not None: sys.stdout.write(out) |
| 68 if err is not None: sys.stderr.write(err) | 85 if err is not None: sys.stderr.write(err) |
| 69 return pipe.returncode | 86 return pipe.returncode |
| 70 except Exception as e: | 87 except Exception as e: |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 if len(extraArgs) != 0: | 144 if len(extraArgs) != 0: |
| 128 optionParser.print_help() | 145 optionParser.print_help() |
| 129 return 1 | 146 return 1 |
| 130 | 147 |
| 131 dart = GetDart() | 148 dart = GetDart() |
| 132 if not exists(dart): | 149 if not exists(dart): |
| 133 print("Dart VM not configured in %s" % dart) | 150 print("Dart VM not configured in %s" % dart) |
| 134 return 1 | 151 return 1 |
| 135 | 152 |
| 136 if subprocess.call("node --help >/dev/null 2>&1", shell=True): | 153 if subprocess.call("node --help >/dev/null 2>&1", shell=True): |
| 137 print "Executing node failed. See frog/README.txt for instructions" | 154 if not exists(D8): |
| 138 return 1 | 155 print "No engine available for running JS code." |
| 156 print "See frog/README.txt for instructions." | |
| 157 return 1 | |
| 158 elif 'node' in options.js_cmd: | |
| 159 options.js_cmd = D8 | |
| 139 | 160 |
| 140 return compileAndRun(options, dartArgs, dart) | 161 return compileAndRun(options, dartArgs, dart) |
| 141 | 162 |
| 142 | 163 |
| 143 def compileAndRun(options, args, dart): | 164 def compileAndRun(options, args, dart): |
| 144 nodeArgs = [] | 165 nodeArgs = [] |
| 145 for i in range(len(args)): | 166 for i in range(len(args)): |
| 146 if args[i].endswith('.dart'): | 167 if args[i].endswith('.dart'): |
| 147 nodeArgs = args[i+1:] | 168 nodeArgs = args[i+1:] |
| 148 args = args[:i+1] | 169 args = args[:i+1] |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 f.close() | 232 f.close() |
| 212 result = execute([browser, outhtml]) | 233 result = execute([browser, outhtml]) |
| 213 | 234 |
| 214 if cleanup: shutil.rmtree(workdir) | 235 if cleanup: shutil.rmtree(workdir) |
| 215 if result != 0: | 236 if result != 0: |
| 216 return 1 | 237 return 1 |
| 217 return 0 | 238 return 0 |
| 218 | 239 |
| 219 if __name__ == '__main__': | 240 if __name__ == '__main__': |
| 220 sys.exit(main(sys.argv)) | 241 sys.exit(main(sys.argv)) |
| OLD | NEW |