OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 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 |
| 4 # BSD-style license that can be found in the LICENSE file. |
| 5 |
| 6 """Wrapper around dartc for use from GYP.""" |
| 7 |
| 8 import optparse |
| 9 import os |
| 10 from os import path |
| 11 import shutil |
| 12 import subprocess |
| 13 import sys |
| 14 |
| 15 |
| 16 def _BuildOptions(): |
| 17 op = optparse.OptionParser(usage='usage: %prog [options] FILE') |
| 18 op.add_option('--out') |
| 19 op.add_option('--dartc') |
| 20 op.add_option('--dartc-option', action='append', dest='dartc_options', |
| 21 default=[]) |
| 22 op.add_option('--incremental', action='store_false', |
| 23 default=os.getenv('DARTC_INCREMENTAL', default=False)) |
| 24 return op |
| 25 |
| 26 |
| 27 def _ParseOptions(cmd_line): |
| 28 op = _BuildOptions() |
| 29 (options, args) = op.parse_args(args=cmd_line) |
| 30 if not options.out: |
| 31 op.error('Flag "--out" not provided') |
| 32 if not options.dartc: |
| 33 op.error('Flag "--dartc" not provided') |
| 34 return (options, args) |
| 35 |
| 36 |
| 37 def main(): |
| 38 (options, args) = _ParseOptions(sys.argv[1:]) |
| 39 if path.exists(options.out): |
| 40 is_out_of_date = path.getmtime(options.dartc) > path.getmtime(options.out) |
| 41 if is_out_of_date or not options.incremental: |
| 42 print 'Deleting %r.' % options.out |
| 43 shutil.rmtree(options.out) |
| 44 command_array = [options.dartc] |
| 45 command_array.extend(['-out', options.out]) |
| 46 command_array.extend(options.dartc_options) |
| 47 command_array.extend(args) |
| 48 print ' '.join([repr(a) for a in command_array]) |
| 49 proc = subprocess.Popen(command_array) |
| 50 proc.communicate() |
| 51 sys.exit(proc.wait()) |
| 52 |
| 53 |
| 54 if __name__ == '__main__': |
| 55 main() |
OLD | NEW |