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

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

Issue 2668353004: Windows: Link library sources into gen_snapshot/dart_bootstrap (Closed)
Patch Set: don't include non-dart files, make symbols static Created 3 years, 10 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
« no previous file with comments | « runtime/lib/libgen_in.cc ('k') | runtime/vm/bootstrap.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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. 4 # BSD-style license that can be found in the LICENSE file.
5 # 5 #
6 # This python script creates a source path mapping in a C++ source file from 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. 7 # a C++ source template and list of dart library files.
8 8
9 import os 9 import os
10 import sys 10 import sys
11 import utils 11 import utils
12 12
13 from os.path import join 13 from os.path import join
14 from optparse import OptionParser 14 from optparse import OptionParser
15 15
16 HOST_OS = utils.GuessOS() 16 HOST_OS = utils.GuessOS()
17 17
18 18
19 def makeString(input_file): 19 def makeString(input_file, var_name):
20 # TODO(iposva): For now avoid creating overly long strings on Windows. 20 result = 'static const char ' + var_name + '[] = {\n '
21 if HOST_OS == 'win32':
22 return 'NULL'
23 result = '"'
24 fileHandle = open(input_file, 'rb') 21 fileHandle = open(input_file, 'rb')
25 lineCounter = 0 22 lineCounter = 0
26 for byte in fileHandle.read(): 23 for byte in fileHandle.read():
27 result += '\\x%02x' % ord(byte) 24 result += '\'\\x%02x' % ord(byte) + '\', '
28 lineCounter += 1 25 lineCounter += 1
29 if lineCounter == 19: 26 if lineCounter == 19:
30 result += '"\n "' 27 result += '\n '
31 lineCounter = 0 28 lineCounter = 0
32 result += '"' 29 result += '0};\n'
33 return result 30 return result
34 31
32 def makeSourceArrays(in_files):
33 result = '';
34 file_count = 0;
35 for string_file in in_files:
36 if string_file.endswith('.dart'):
37 file_count += 1
38 file_string = makeString(string_file, "source_array_" + str(file_count))
39 result += file_string
40 return result
35 41
36 def makeFile(output_file, input_cc_file, include, var_name, lib_name, in_files): 42 def makeFile(output_file, input_cc_file, include, var_name, lib_name, in_files):
37 part_index = [ ] 43 part_index = [ ]
38 bootstrap_cc_text = open(input_cc_file).read() 44 bootstrap_cc_text = open(input_cc_file).read()
45 bootstrap_cc_text = bootstrap_cc_text.replace("{{SOURCE_ARRAYS}}", makeSourceA rrays(in_files))
39 bootstrap_cc_text = bootstrap_cc_text.replace("{{INCLUDE}}", include) 46 bootstrap_cc_text = bootstrap_cc_text.replace("{{INCLUDE}}", include)
40 bootstrap_cc_text = bootstrap_cc_text.replace("{{VAR_NAME}}", var_name) 47 bootstrap_cc_text = bootstrap_cc_text.replace("{{VAR_NAME}}", var_name)
41 main_file_found = False 48 main_file_found = False
49 file_count = 0
42 for string_file in in_files: 50 for string_file in in_files:
43 if string_file.endswith('.dart'): 51 if string_file.endswith('.dart'):
52 file_count += 1
44 if (not main_file_found): 53 if (not main_file_found):
45 inpt = open(string_file, 'r') 54 inpt = open(string_file, 'r')
46 for line in inpt: 55 for line in inpt:
47 # File with library tag is the main file. 56 # File with library tag is the main file.
48 if line.startswith('library '): 57 if line.startswith('library '):
49 main_file_found = True 58 main_file_found = True
50 bootstrap_cc_text = bootstrap_cc_text.replace( 59 bootstrap_cc_text = bootstrap_cc_text.replace(
51 "{{LIBRARY_SOURCE_MAP}}", 60 "{{LIBRARY_SOURCE_MAP}}",
52 ' "' + lib_name + '",\n "' + 61 ' "' + lib_name + '",\n "' +
53 os.path.abspath(string_file).replace('\\', '\\\\') + '",\n' + 62 os.path.abspath(string_file).replace('\\', '\\\\') + '",\n' +
54 ' ' + makeString(string_file) + ',\n') 63 ' source_array_' + str(file_count) + ',\n')
55 inpt.close() 64 inpt.close()
56 if (main_file_found): 65 if (main_file_found):
57 continue 66 continue
58 part_index.append(' "' + 67 part_index.append(' "' +
59 os.path.basename(string_file).replace('\\', '\\\\') + '",\n') 68 os.path.basename(string_file).replace('\\', '\\\\') + '",\n')
60 part_index.append(' "' + 69 part_index.append(' "' +
61 os.path.abspath(string_file).replace('\\', '\\\\') + '",\n') 70 os.path.abspath(string_file).replace('\\', '\\\\') + '",\n')
62 part_index.append(' ' + makeString(string_file) + ',\n\n') 71 part_index.append(' source_array_' + str(file_count) + ',\n\n')
63 bootstrap_cc_text = bootstrap_cc_text.replace("{{LIBRARY_SOURCE_MAP}}", '') 72 bootstrap_cc_text = bootstrap_cc_text.replace("{{LIBRARY_SOURCE_MAP}}", '')
64 bootstrap_cc_text = bootstrap_cc_text.replace("{{PART_SOURCE_MAP}}", 73 bootstrap_cc_text = bootstrap_cc_text.replace("{{PART_SOURCE_MAP}}",
65 ''.join(part_index)) 74 ''.join(part_index))
66 open(output_file, 'w').write(bootstrap_cc_text) 75 open(output_file, 'w').write(bootstrap_cc_text)
67 return True 76 return True
68 77
69
70 def main(args): 78 def main(args):
71 try: 79 try:
72 # Parse input. 80 # Parse input.
73 parser = OptionParser() 81 parser = OptionParser()
74 parser.add_option("--output", 82 parser.add_option("--output",
75 action="store", type="string", 83 action="store", type="string",
76 help="output file name") 84 help="output file name")
77 parser.add_option("--input_cc", 85 parser.add_option("--input_cc",
78 action="store", type="string", 86 action="store", type="string",
79 help="input template file") 87 help="input template file")
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 129
122 return 0 130 return 0
123 except Exception, inst: 131 except Exception, inst:
124 sys.stderr.write('gen_library_src_paths.py exception\n') 132 sys.stderr.write('gen_library_src_paths.py exception\n')
125 sys.stderr.write(str(inst)) 133 sys.stderr.write(str(inst))
126 sys.stderr.write('\n') 134 sys.stderr.write('\n')
127 return -1 135 return -1
128 136
129 if __name__ == '__main__': 137 if __name__ == '__main__':
130 sys.exit(main(sys.argv)) 138 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « runtime/lib/libgen_in.cc ('k') | runtime/vm/bootstrap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698