Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: runtime/tools/gen_library_src_paths.py

Issue 14786012: Second step towards loading the core library scripts directly from the sources (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 for string_file in in_files:
22 main_file = False
23 if string_file.endswith('.dart'):
24 inpt = open(string_file, 'r')
25 for line in inpt:
26 # File with library tag is the main file.
27 if line.startswith('library '):
Ivan Posva 2013/05/02 21:42:58 This will iterate all the way through the file and
siva 2013/05/03 01:58:32 I didn't want to make the assumption that the firs
28 main_file = True
29 inpt.close()
30 if (main_file):
31 bootstrap_cc_text = bootstrap_cc_text.replace("{{LIBRARY_SOURCE_MAP}}",
32 ' "' + lib_name + '", "' +
33 os.path.abspath(string_file) + '", \n')
34 else:
35 part_index.append(' "' + os.path.basename(string_file) + '", ')
36 part_index.append('"' + os.path.abspath(string_file) + '", \n')
37 bootstrap_cc_text = bootstrap_cc_text.replace("{{PART_SOURCE_MAP}}",
38 ''.join(part_index))
39 open(output_file, 'w').write(bootstrap_cc_text)
40 return True
41
42
43 def main(args):
44 try:
45 # Parse input.
46 parser = OptionParser()
47 parser.add_option("--output",
48 action="store", type="string",
49 help="output file name")
50 parser.add_option("--input_cc",
51 action="store", type="string",
52 help="input template file")
53 parser.add_option("--include",
54 action="store", type="string",
55 help="variable name")
56 parser.add_option("--library_name",
57 action="store", type="string",
58 help="library name")
59 parser.add_option("--var_name",
60 action="store", type="string",
61 help="variable name")
62
63 (options, args) = parser.parse_args()
64 if not options.output:
65 sys.stderr.write('--output not specified\n')
66 return -1
67 if not len(options.input_cc):
68 sys.stderr.write('--input_cc not specified\n')
69 return -1
70 if not len(options.include):
71 sys.stderr.write('--include not specified\n')
72 return -1
73 if not len(options.var_name):
74 sys.stderr.write('--var_name not specified\n')
75 return -1
76 if not len(options.library_name):
77 sys.stderr.write('--library_name not specified\n')
78 return -1
79 if len(args) == 0:
80 sys.stderr.write('No input files specified\n')
81 return -1
82
83 files = [ ]
84 for arg in args:
85 files.append(arg)
86
87 if not makeFile(options.output,
88 options.input_cc,
89 options.include,
90 options.var_name,
91 options.library_name,
92 files):
93 return -1
94
95 return 0
96 except Exception, inst:
97 sys.stderr.write('gen_library_src_paths.py exception\n')
98 sys.stderr.write(str(inst))
99 sys.stderr.write('\n')
100 return -1
101
102 if __name__ == '__main__':
103 sys.exit(main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698