| OLD | NEW |
| 1 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 # for details. All rights reserved. Use of this source code is governed by a | 2 # for details. All rights reserved. Use of this source code is governed by a |
| 3 # BSD-style license that can be found in the LICENSE file. | 3 # BSD-style license that can be found in the LICENSE file. |
| 4 # | 4 # |
| 5 # This python script creates a string literal in a C++ source file from a C++ | 5 # This python script creates a string literal in a C++ source file from a C++ |
| 6 # source template and text file. | 6 # source template and text file. |
| 7 | 7 |
| 8 import os | 8 import os |
| 9 import sys | 9 import sys |
| 10 from os.path import join | 10 from os.path import join |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 lineCounter += 1 | 24 lineCounter += 1 |
| 25 if lineCounter == 10: | 25 if lineCounter == 10: |
| 26 result += '\n ' | 26 result += '\n ' |
| 27 lineCounter = 0 | 27 lineCounter = 0 |
| 28 if lineCounter != 0: | 28 if lineCounter != 0: |
| 29 result += '\n ' | 29 result += '\n ' |
| 30 result += ' // Terminating null character.\n 0' | 30 result += ' // Terminating null character.\n 0' |
| 31 return result | 31 return result |
| 32 | 32 |
| 33 | 33 |
| 34 def makeFile(output_file, input_cc_file, input_files): | 34 def makeFile(output_file, input_cc_file, include, var_name, input_files): |
| 35 bootstrap_cc_text = open(input_cc_file).read() | 35 bootstrap_cc_text = open(input_cc_file).read() |
| 36 bootstrap_cc_text = bootstrap_cc_text.replace("{{INCLUDE}}", include) |
| 37 bootstrap_cc_text = bootstrap_cc_text.replace("{{VAR_NAME}}", var_name) |
| 36 bootstrap_cc_text = bootstrap_cc_text.replace("{{DART_SOURCE}}", | 38 bootstrap_cc_text = bootstrap_cc_text.replace("{{DART_SOURCE}}", |
| 37 makeString(input_files)) | 39 makeString(input_files)) |
| 38 open(output_file, 'w').write(bootstrap_cc_text) | 40 open(output_file, 'w').write(bootstrap_cc_text) |
| 39 return True | 41 return True |
| 40 | 42 |
| 41 | 43 |
| 42 def main(args): | 44 def main(args): |
| 43 try: | 45 try: |
| 44 # Parse input. | 46 # Parse input. |
| 45 parser = OptionParser() | 47 parser = OptionParser() |
| 46 parser.add_option("--output", | 48 parser.add_option("--output", |
| 47 action="store", type="string", | 49 action="store", type="string", |
| 48 help="output file name") | 50 help="output file name") |
| 49 parser.add_option("--input_cc", | 51 parser.add_option("--input_cc", |
| 50 action="store", type="string", | 52 action="store", type="string", |
| 51 help="input template file") | 53 help="input template file") |
| 54 parser.add_option("--include", |
| 55 action="store", type="string", |
| 56 help="variable name") |
| 57 parser.add_option("--var_name", |
| 58 action="store", type="string", |
| 59 help="variable name") |
| 52 | 60 |
| 53 (options, args) = parser.parse_args() | 61 (options, args) = parser.parse_args() |
| 54 if not options.output: | 62 if not options.output: |
| 55 sys.stderr.write('--output not specified\n') | 63 sys.stderr.write('--output not specified\n') |
| 56 return -1 | 64 return -1 |
| 57 if not len(options.input_cc): | 65 if not len(options.input_cc): |
| 58 sys.stderr.write('--input_cc not specified\n') | 66 sys.stderr.write('--input_cc not specified\n') |
| 59 return -1 | 67 return -1 |
| 68 if not len(options.include): |
| 69 sys.stderr.write('--include not specified\n') |
| 70 return -1 |
| 71 if not len(options.var_name): |
| 72 sys.stderr.write('--var_name not specified\n') |
| 73 return -1 |
| 60 if len(args) == 0: | 74 if len(args) == 0: |
| 61 sys.stderr.write('No input files specified\n') | 75 sys.stderr.write('No input files specified\n') |
| 62 return -1 | 76 return -1 |
| 63 | 77 |
| 64 files = [ ] | 78 files = [ ] |
| 65 for arg in args: | 79 for arg in args: |
| 66 files.append(arg) | 80 files.append(arg) |
| 67 | 81 |
| 68 if not makeFile(options.output, options.input_cc, files): | 82 if not makeFile(options.output, |
| 83 options.input_cc, |
| 84 options.include, |
| 85 options.var_name, |
| 86 files): |
| 69 return -1 | 87 return -1 |
| 70 | 88 |
| 71 return 0 | 89 return 0 |
| 72 except Exception, inst: | 90 except Exception, inst: |
| 73 sys.stderr.write('create_string_literal.py exception\n') | 91 sys.stderr.write('create_string_literal.py exception\n') |
| 74 sys.stderr.write(str(inst)) | 92 sys.stderr.write(str(inst)) |
| 75 sys.stderr.write('\n') | 93 sys.stderr.write('\n') |
| 76 return -1 | 94 return -1 |
| 77 | 95 |
| 78 if __name__ == '__main__': | 96 if __name__ == '__main__': |
| 79 sys.exit(main(sys.argv)) | 97 sys.exit(main(sys.argv)) |
| OLD | NEW |