OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2013, 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 # This python script creates a source path mapping in a C++ source file from |
| 7 # a C++ source template and list of dart library files. |
| 8 |
| 9 import os |
| 10 import sys |
| 11 |
| 12 from os.path import join |
| 13 from optparse import OptionParser |
| 14 |
| 15 |
| 16 def makeFile(output_file, input_cc_file, include, var_name, lib_name, in_files): |
| 17 part_index = [ ] |
| 18 bootstrap_cc_text = open(input_cc_file).read() |
| 19 bootstrap_cc_text = bootstrap_cc_text.replace("{{INCLUDE}}", include) |
| 20 bootstrap_cc_text = bootstrap_cc_text.replace("{{VAR_NAME}}", var_name) |
| 21 main_file_found = False |
| 22 for string_file in in_files: |
| 23 if string_file.endswith('.dart'): |
| 24 if (not main_file_found): |
| 25 inpt = open(string_file, 'r') |
| 26 for line in inpt: |
| 27 # File with library tag is the main file. |
| 28 if line.startswith('library '): |
| 29 main_file_found = True |
| 30 bootstrap_cc_text = bootstrap_cc_text.replace( |
| 31 "{{LIBRARY_SOURCE_MAP}}", |
| 32 ' "' + lib_name + '", "' + |
| 33 os.path.abspath(string_file) + '", \n') |
| 34 inpt.close() |
| 35 if (main_file_found): |
| 36 continue |
| 37 part_index.append(' "' + os.path.basename(string_file) + '", ') |
| 38 part_index.append('"' + os.path.abspath(string_file) + '", \n') |
| 39 bootstrap_cc_text = bootstrap_cc_text.replace("{{PART_SOURCE_MAP}}", |
| 40 ''.join(part_index)) |
| 41 open(output_file, 'w').write(bootstrap_cc_text) |
| 42 return True |
| 43 |
| 44 |
| 45 def main(args): |
| 46 try: |
| 47 # Parse input. |
| 48 parser = OptionParser() |
| 49 parser.add_option("--output", |
| 50 action="store", type="string", |
| 51 help="output file name") |
| 52 parser.add_option("--input_cc", |
| 53 action="store", type="string", |
| 54 help="input template file") |
| 55 parser.add_option("--include", |
| 56 action="store", type="string", |
| 57 help="variable name") |
| 58 parser.add_option("--library_name", |
| 59 action="store", type="string", |
| 60 help="library name") |
| 61 parser.add_option("--var_name", |
| 62 action="store", type="string", |
| 63 help="variable name") |
| 64 |
| 65 (options, args) = parser.parse_args() |
| 66 if not options.output: |
| 67 sys.stderr.write('--output not specified\n') |
| 68 return -1 |
| 69 if not len(options.input_cc): |
| 70 sys.stderr.write('--input_cc not specified\n') |
| 71 return -1 |
| 72 if not len(options.include): |
| 73 sys.stderr.write('--include not specified\n') |
| 74 return -1 |
| 75 if not len(options.var_name): |
| 76 sys.stderr.write('--var_name not specified\n') |
| 77 return -1 |
| 78 if not len(options.library_name): |
| 79 sys.stderr.write('--library_name not specified\n') |
| 80 return -1 |
| 81 if len(args) == 0: |
| 82 sys.stderr.write('No input files specified\n') |
| 83 return -1 |
| 84 |
| 85 files = [ ] |
| 86 for arg in args: |
| 87 files.append(arg) |
| 88 |
| 89 if not makeFile(options.output, |
| 90 options.input_cc, |
| 91 options.include, |
| 92 options.var_name, |
| 93 options.library_name, |
| 94 files): |
| 95 return -1 |
| 96 |
| 97 return 0 |
| 98 except Exception, inst: |
| 99 sys.stderr.write('gen_library_src_paths.py exception\n') |
| 100 sys.stderr.write(str(inst)) |
| 101 sys.stderr.write('\n') |
| 102 return -1 |
| 103 |
| 104 if __name__ == '__main__': |
| 105 sys.exit(main(sys.argv)) |
OLD | NEW |