generator.py revision 5821806d5e7f356e8fa4b058a389a808ea183019
1#!/usr/bin/env python
2# Copyright (c) 2012 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import os
7import sys
8import traceback
9
10# Note: some of these files are imported to register cmdline options.
11from idl_generator import Generator
12from idl_option import ParseOptions
13from idl_outfile import IDLOutFile
14from idl_parser import ParseFiles
15from idl_c_header import HGen
16from idl_gen_pnacl import PnaclGen
17
18
19def Main(args):
20  # If no arguments are provided, assume we are trying to rebuild the
21  # C headers with warnings off.
22  try:
23    if not args:
24      args = [
25          '--wnone', '--cgen', '--range=start,end',
26          '--pnacl', '--pnaclshim',
27          '../native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c',
28      ]
29      current_dir = os.path.abspath(os.getcwd())
30      script_dir = os.path.abspath(os.path.dirname(__file__))
31      if current_dir != script_dir:
32        print '\nIncorrect CWD, default run skipped.'
33        print 'When running with no arguments set CWD to the scripts directory:'
34        print '\t' + script_dir + '\n'
35        print 'This ensures correct default paths and behavior.\n'
36        return 1
37
38    filenames = ParseOptions(args)
39    ast = ParseFiles(filenames)
40    if ast.errors:
41      print 'Found %d errors.  Aborting build.\n' % ast.errors
42      return 1
43    return Generator.Run(ast)
44  except SystemExit, ec:
45    print 'Exiting with %d' % ec.code
46    sys.exit(ec.code)
47
48  except:
49    typeinfo, value, tb = sys.exc_info()
50    traceback.print_exception(typeinfo, value, tb)
51    print 'Called with: ' + ' '.join(sys.argv)
52
53
54if __name__ == '__main__':
55    sys.exit(Main(sys.argv[1:]))
56
57