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 6 import os 7 import sys 8 import traceback 9 10 # Note: some of these files are imported to register cmdline options. 11 from idl_generator import Generator 12 from idl_option import ParseOptions 13 from idl_outfile import IDLOutFile 14 from idl_parser import ParseFiles 15 from idl_c_header import HGen 16 from idl_thunk import TGen 17 from idl_gen_pnacl import PnaclGen 18 19 20 def Main(args): 21 # If no arguments are provided, assume we are trying to rebuild the 22 # C headers with warnings off. 23 try: 24 if not args: 25 args = [ 26 '--wnone', '--cgen', '--range=start,end', 27 '--pnacl', '--pnaclshim', 28 '../native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c', 29 '--tgen', 30 ] 31 current_dir = os.path.abspath(os.getcwd()) 32 script_dir = os.path.abspath(os.path.dirname(__file__)) 33 if current_dir != script_dir: 34 print '\nIncorrect CWD, default run skipped.' 35 print 'When running with no arguments set CWD to the scripts directory:' 36 print '\t' + script_dir + '\n' 37 print 'This ensures correct default paths and behavior.\n' 38 return 1 39 40 filenames = ParseOptions(args) 41 ast = ParseFiles(filenames) 42 if ast.errors: 43 print 'Found %d errors. Aborting build.\n' % ast.errors 44 return 1 45 return Generator.Run(ast) 46 except SystemExit, ec: 47 print 'Exiting with %d' % ec.code 48 sys.exit(ec.code) 49 50 except: 51 typeinfo, value, tb = sys.exc_info() 52 traceback.print_exception(typeinfo, value, tb) 53 print 'Called with: ' + ' '.join(sys.argv) 54 55 56 if __name__ == '__main__': 57 sys.exit(Main(sys.argv[1:])) 58