| 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. |
| 11 | 11 |
| 12 | 12 |
| 13 import optparse | 13 import optparse |
| 14 import os | 14 import os |
| 15 import platform | 15 import platform |
| 16 import tempfile | 16 import tempfile |
| 17 import shutil | 17 import shutil |
| 18 import subprocess | 18 import subprocess |
| 19 import sys | 19 import sys |
| 20 | 20 |
| 21 | 21 |
| 22 from os.path import dirname, join, realpath, exists | 22 from os.path import dirname, join, realpath, exists, basename, relpath |
| 23 | 23 |
| 24 HOME = dirname(realpath(__file__)) | 24 HOME = dirname(realpath(__file__)) |
| 25 sys.path.append(join(HOME, os.pardir, 'tools')) | 25 sys.path.append(join(HOME, os.pardir, 'tools')) |
| 26 import utils | 26 import utils |
| 27 | 27 |
| 28 HTML = '''<html> | 28 HTML = '''<html> |
| 29 <head><title>Frog</title><head> | 29 <head><title>Frog</title><head> |
| 30 <body> | 30 <body> |
| 31 <script type="application/javascript" src="out.js"></script> | 31 <script type="application/javascript" src="out.js"></script> |
| 32 </body> | 32 </body> |
| 33 </html> | 33 </html> |
| 34 ''' | 34 ''' |
| 35 | 35 |
| 36 def GetDart(): | 36 def GetDart(): |
| 37 # Try a release version | 37 # Get the release version. |
| 38 dart = utils.GetDartRunner('release', 'ia32', 'vm') | 38 return utils.GetDartRunner('release', 'ia32', 'vm') |
| 39 if exists(dart): return dart | |
| 40 # Try at the top level | |
| 41 dart = join(os.pardir, dart) | |
| 42 if exists(dart): return dart | |
| 43 | 39 |
| 44 # Try a debug version | 40 def GetReleaseVersion(dart): |
| 45 dart = utils.GetDartRunner('debug', 'ia32', 'vm') | 41 product_dir = dirname(dart) |
| 46 if exists(dart): return dart | 42 out_dir = dirname(product_dir) |
| 47 # Try at the top level | 43 config = basename(product_dir) |
| 48 dart = join(os.pardir, dart) | 44 |
| 49 return dart | 45 if config.find('Debug') != -1: |
| 46 dart_release = join(out_dir, config.replace('Debug', 'Release'), 'dart') |
| 47 else: |
| 48 dart_release = dart |
| 49 |
| 50 return dart_release |
| 50 | 51 |
| 51 def GetD8(): | 52 def GetD8(): |
| 52 system = utils.GuessOS() | 53 return join(dirname(GetDart()), 'd8') |
| 53 d8 = join(utils.GetBuildRoot(system, 'release', 'ia32'), 'd8') | |
| 54 if exists(d8): return d8 | |
| 55 # Try at the top level | |
| 56 d8 = join(os.pardir, d8) | |
| 57 if exists(d8): return d8 | |
| 58 | |
| 59 # Try a debug version | |
| 60 d8 = join(utils.GetBuildRoot(system, 'debug', 'ia32'), 'd8') | |
| 61 if exists(d8): return d8 | |
| 62 # Try at the top level | |
| 63 d8 = join(os.pardir, d8) | |
| 64 return d8 | |
| 65 | 54 |
| 66 D8 = GetD8() | 55 D8 = GetD8() |
| 67 | 56 |
| 68 def execute(cmd): | 57 def execute(cmd): |
| 69 """Execute a command in a subprocess. """ | 58 """Execute a command in a subprocess. """ |
| 70 try: | 59 try: |
| 71 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 60 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 72 out, err = pipe.communicate() | 61 out, err = pipe.communicate() |
| 73 if out is not None: sys.stdout.write(out) | 62 if out is not None: sys.stdout.write(out) |
| 74 if err is not None: sys.stderr.write(err) | 63 if err is not None: sys.stderr.write(err) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 85 default=None, | 74 default=None, |
| 86 metavar='DIR', help='Directory where temporary files are created.') | 75 metavar='DIR', help='Directory where temporary files are created.') |
| 87 | 76 |
| 88 # Meta-flag for VM running compiler, probably want more options here. | 77 # Meta-flag for VM running compiler, probably want more options here. |
| 89 optionParser.add_option('--vm_flags', | 78 optionParser.add_option('--vm_flags', |
| 90 # TODO(jimhug): Make it easier to enable and disable this for tests. | 79 # TODO(jimhug): Make it easier to enable and disable this for tests. |
| 91 #default='--enable_type_checks --enable_asserts', | 80 #default='--enable_type_checks --enable_asserts', |
| 92 default='', | 81 default='', |
| 93 help='Flags to pass to the VM that is running frog itself.') | 82 help='Flags to pass to the VM that is running frog itself.') |
| 94 | 83 |
| 84 optionParser.add_option('--vm', |
| 85 default=GetDart(), |
| 86 help='The location of the VM.') |
| 87 |
| 95 optionParser.add_option('--js_cmd', | 88 optionParser.add_option('--js_cmd', |
| 96 default = 'node --crankshaft', # node is really slow without this. | 89 default = 'node --crankshaft', # node is really slow without this. |
| 97 metavar='FILE', help='The shell cmd to use to run output JS code.') | 90 metavar='FILE', help='The shell cmd to use to run output JS code.') |
| 98 | 91 |
| 99 optionParser.add_option('--keep_files', | 92 optionParser.add_option('--keep_files', |
| 100 action='store_true', help='Do not remove temporary files.') | 93 action='store_true', help='Do not remove temporary files.') |
| 101 | 94 |
| 102 # TODO(vsm): Hook in HtmlConverter. | 95 # TODO(vsm): Hook in HtmlConverter. |
| 103 optionParser.add_option('--html', | 96 optionParser.add_option('--html', |
| 104 action='store_true', help='Invoke this in the browser instead of node/d8.'
) | 97 action='store_true', help='Invoke this in the browser instead of node/d8.'
) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 124 | 117 |
| 125 options, extraArgs = parseOptions(pythonArgs) | 118 options, extraArgs = parseOptions(pythonArgs) |
| 126 if options.verbose: | 119 if options.verbose: |
| 127 print ("dartArgs=%s pythonArgs=%s extraArgs=%s" % | 120 print ("dartArgs=%s pythonArgs=%s extraArgs=%s" % |
| 128 (' '.join(dartArgs), ' '.join(pythonArgs), ' '.join(extraArgs))) | 121 (' '.join(dartArgs), ' '.join(pythonArgs), ' '.join(extraArgs))) |
| 129 | 122 |
| 130 if len(extraArgs) != 0: | 123 if len(extraArgs) != 0: |
| 131 optionParser.print_help() | 124 optionParser.print_help() |
| 132 return 1 | 125 return 1 |
| 133 | 126 |
| 134 dart = GetDart() | 127 dart = GetReleaseVersion(options.vm) |
| 135 if not exists(dart): | 128 if not exists(dart): |
| 136 print("Dart VM not configured in %s," % dart), | 129 print "Dart VM not built. Please run the following command:" |
| 137 print "run the following command from the dart directory" | 130 build_file = relpath(join(HOME, os.pardir, 'tools', 'build.py')) |
| 138 print " tools/build.py -m release" | 131 print ' ' + build_file + ' -m release' |
| 139 return 1 | 132 return 1 |
| 140 | 133 |
| 141 if subprocess.call("node --help >/dev/null 2>&1", shell=True): | 134 if subprocess.call("node --help >/dev/null 2>&1", shell=True): |
| 142 if not exists(D8): | 135 if not exists(D8): |
| 143 print "No engine available for running JS code." | 136 print "No engine available for running JS code." |
| 144 print "See frog/README.txt for instructions." | 137 print "See frog/README.txt for instructions." |
| 145 return 1 | 138 return 1 |
| 146 elif 'node' in options.js_cmd: | 139 elif 'node' in options.js_cmd: |
| 147 options.js_cmd = D8 | 140 options.js_cmd = D8 |
| 148 | 141 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 f.close() | 213 f.close() |
| 221 result = execute([browser, outhtml]) | 214 result = execute([browser, outhtml]) |
| 222 | 215 |
| 223 if cleanup: shutil.rmtree(workdir) | 216 if cleanup: shutil.rmtree(workdir) |
| 224 if result != 0: | 217 if result != 0: |
| 225 return 1 | 218 return 1 |
| 226 return 0 | 219 return 0 |
| 227 | 220 |
| 228 if __name__ == '__main__': | 221 if __name__ == '__main__': |
| 229 sys.exit(main(sys.argv)) | 222 sys.exit(main(sys.argv)) |
| OLD | NEW |