| 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(): |
| 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 D8 = GetD8() |
| 61 | 77 |
| 62 def execute(cmd): | 78 def execute(cmd): |
| 63 """Execute a command in a subprocess. """ | 79 """Execute a command in a subprocess. """ |
| 64 try: | 80 try: |
| 65 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 81 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 66 out, err = pipe.communicate() | 82 out, err = pipe.communicate() |
| 67 if out is not None: sys.stdout.write(out) | 83 if out is not None: sys.stdout.write(out) |
| 68 if err is not None: sys.stderr.write(err) | 84 if err is not None: sys.stderr.write(err) |
| 69 return pipe.returncode | 85 return pipe.returncode |
| 70 except Exception as e: | 86 except Exception as e: |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 if len(extraArgs) != 0: | 143 if len(extraArgs) != 0: |
| 128 optionParser.print_help() | 144 optionParser.print_help() |
| 129 return 1 | 145 return 1 |
| 130 | 146 |
| 131 dart = GetDart() | 147 dart = GetDart() |
| 132 if not exists(dart): | 148 if not exists(dart): |
| 133 print("Dart VM not configured in %s" % dart) | 149 print("Dart VM not configured in %s" % dart) |
| 134 return 1 | 150 return 1 |
| 135 | 151 |
| 136 if subprocess.call("node --help >/dev/null 2>&1", shell=True): | 152 if subprocess.call("node --help >/dev/null 2>&1", shell=True): |
| 137 print "Executing node failed. See frog/README.txt for instructions" | 153 if not exists(D8): |
| 138 return 1 | 154 print "No engine available for running JS code." |
| 155 print "See frog/README.txt for instructions." |
| 156 return 1 |
| 157 elif 'node' in options.js_cmd: |
| 158 options.js_cmd = D8 |
| 139 | 159 |
| 140 return compileAndRun(options, dartArgs, dart) | 160 return compileAndRun(options, dartArgs, dart) |
| 141 | 161 |
| 142 | 162 |
| 143 def compileAndRun(options, args, dart): | 163 def compileAndRun(options, args, dart): |
| 144 nodeArgs = [] | 164 nodeArgs = [] |
| 145 for i in range(len(args)): | 165 for i in range(len(args)): |
| 146 if args[i].endswith('.dart'): | 166 if args[i].endswith('.dart'): |
| 147 nodeArgs = args[i+1:] | 167 nodeArgs = args[i+1:] |
| 148 args = args[:i+1] | 168 args = args[:i+1] |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 f.close() | 231 f.close() |
| 212 result = execute([browser, outhtml]) | 232 result = execute([browser, outhtml]) |
| 213 | 233 |
| 214 if cleanup: shutil.rmtree(workdir) | 234 if cleanup: shutil.rmtree(workdir) |
| 215 if result != 0: | 235 if result != 0: |
| 216 return 1 | 236 return 1 |
| 217 return 0 | 237 return 0 |
| 218 | 238 |
| 219 if __name__ == '__main__': | 239 if __name__ == '__main__': |
| 220 sys.exit(main(sys.argv)) | 240 sys.exit(main(sys.argv)) |
| OLD | NEW |