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

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

Issue 27530002: Reorganize VM Service client (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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
1 # Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 # Copyright (c) 2013, 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 string literals in a C++ source file from a C++ 5 # This python script creates string literals in a C++ source file from a C++
6 # source template and one or more resource files. 6 # source template and one or more resource files.
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
11 import time 11 import time
12 from optparse import OptionParser 12 from optparse import OptionParser
13 import re 13 import re
14 from datetime import date 14 from datetime import date
15 15
16 def makeResources(root_dir, package_dir, third_party_dir, rebase, input_files): 16 def makeResources(root_dir, input_files):
17 result = '' 17 result = ''
18 resources = [] 18 resources = []
19 19
20 # Write each file's contents as a byte string constant. 20 # Write each file's contents as a byte string constant.
21 for resource_file in input_files: 21 for resource_file in input_files:
22 if root_dir and resource_file.startswith(root_dir): 22 if root_dir and resource_file.startswith(root_dir):
23 resource_file_name = resource_file[ len(root_dir) : ] 23 resource_file_name = resource_file[ len(root_dir) : ]
24 elif package_dir and resource_file.startswith(package_dir):
25 resource_file_name = os.path.join(rebase,
26 resource_file[ len(package_dir) : ])
27 elif third_party_dir and resource_file.startswith(third_party_dir):
28 resource_file_name = os.path.join(rebase,
29 resource_file[ len(third_party_dir) : ])
30 else: 24 else:
31 resource_file_name = resource_file 25 resource_file_name = resource_file
32
33 resource_url = '/%s' % resource_file_name 26 resource_url = '/%s' % resource_file_name
34 result += '// %s\n' % resource_file 27 result += '// %s\n' % resource_file
35 result += 'const char ' 28 result += 'const char '
36 resource_name = re.sub(r'(/|\.|-)', '_', resource_file_name) + '_' 29 resource_name = re.sub(r'(/|\.|-)', '_', resource_file_name) + '_'
37 result += resource_name 30 result += resource_name
38 result += '[] = {\n ' 31 result += '[] = {\n '
39 fileHandle = open(resource_file, 'rb') 32 fileHandle = open(resource_file, 'rb')
40 lineCounter = 0 33 lineCounter = 0
41 for byte in fileHandle.read(): 34 for byte in fileHandle.read():
42 result += ' %d,' % ord(byte) 35 result += ' %d,' % ord(byte)
(...skipping 11 matching lines...) Expand all
54 result += 'Resources::resource_map_entry Resources::builtin_resources_[] = ' 47 result += 'Resources::resource_map_entry Resources::builtin_resources_[] = '
55 result += '{\n' 48 result += '{\n'
56 for res in resources: 49 for res in resources:
57 result += ' { "%s", %s, %d },\n' % res 50 result += ' { "%s", %s, %d },\n' % res
58 result += '};\n\n' 51 result += '};\n\n'
59 result += 'const intptr_t Resources::builtin_resources_count_ ' 52 result += 'const intptr_t Resources::builtin_resources_count_ '
60 result += '= %d;\n' % len(resources) 53 result += '= %d;\n' % len(resources)
61 return result 54 return result
62 55
63 56
64 def makeFile(output_file, root_dir, package_dir, third_party_dir, rebase_dir, 57 def makeFile(output_file, root_dir, input_files):
65 input_files):
66 cc_text = ''' 58 cc_text = '''
67 // Copyright (c) %d, the Dart project authors. Please see the AUTHORS file 59 // Copyright (c) %d, the Dart project authors. Please see the AUTHORS file
68 // for details. All rights reserved. Use of this source code is governed by a 60 // for details. All rights reserved. Use of this source code is governed by a
69 // BSD-style license that can be found in the LICENSE file. 61 // BSD-style license that can be found in the LICENSE file.
70 62
71 ''' % date.today().year 63 ''' % date.today().year
72 cc_text += '#include "bin/resources.h"\n\n' 64 cc_text += '#include "bin/resources.h"\n\n'
73 cc_text += 'namespace dart {\n' 65 cc_text += 'namespace dart {\n'
74 cc_text += 'namespace bin {\n' 66 cc_text += 'namespace bin {\n'
75 cc_text += makeResources(root_dir, package_dir, third_party_dir, rebase_dir, 67 cc_text += makeResources(root_dir, input_files)
76 input_files)
77 cc_text += '} // namespace bin\n} // namespace dart\n' 68 cc_text += '} // namespace bin\n} // namespace dart\n'
Ivan Posva 2013/10/16 17:31:11 cc_text += '} // namespace bin\n' cc_text += '}
Cutch 2013/10/16 17:35:29 Done.
78 open(output_file, 'w').write(cc_text) 69 open(output_file, 'w').write(cc_text)
79 return True 70 return True
80 71
81 72
82 def makeFileList(input_file_name, root_prefix, package_dir):
83 product_dir = '<(PRODUCT_DIR)/'
84 file = open(input_file_name, 'rb')
85 gyp_contents = eval(file.read())
86 files = []
87 for input_file in gyp_contents['sources']:
88 if input_file.startswith(product_dir):
89 files.append(os.path.join(package_dir, input_file[ len(product_dir) : ]))
90 else:
91 files.append(os.path.join(root_prefix, input_file))
92 return files
93
94
95 def main(args): 73 def main(args):
96 try: 74 try:
97 # Parse input. 75 # Parse input.
98 parser = OptionParser() 76 parser = OptionParser()
99 parser.add_option("--output", 77 parser.add_option("--output",
100 action="store", type="string", 78 action="store", type="string",
101 help="output file name") 79 help="output file name")
102 parser.add_option("--root_prefix", 80 parser.add_option("--root_prefix",
103 action="store", type="string", 81 action="store", type="string",
104 help="root directory for resources") 82 help="root directory for resources")
105 parser.add_option("--package_dir",
106 action="store", type="string",
107 help="root directory for package resources")
108 parser.add_option("--third_party_dir",
109 action="store", type="string",
110 help="root directory for third party resources")
111 parser.add_option("--rebase",
112 action="store", type="string",
113 help="base directory for package/third_party resources")
114
115 (options, args) = parser.parse_args() 83 (options, args) = parser.parse_args()
116 if not options.output: 84 if not options.output:
117 sys.stderr.write('--output not specified\n') 85 sys.stderr.write('--output not specified\n')
118 return -1 86 return -1
119 if not options.root_prefix:
120 sys.stderr.write('--root_prefix not specified\n')
121 return -1
122 if not options.package_dir:
123 sys.stderr.write('--package_dir not specified\n')
124 return -1
125 if not options.third_party_dir:
126 sys.stderr.write('--third_party_dir not specified\n')
127 return -1
128 if not options.rebase:
129 sys.stderr.write('--rebase not specified\n')
130 return -1
131 if len(args) == 0: 87 if len(args) == 0:
132 sys.stderr.write('No input files specified\n') 88 sys.stderr.write('No input files specified\n')
133 return -1 89 return -1
134 90
135 files = makeFileList(args[0], options.root_prefix, options.package_dir) 91 files = [ ]
136 for file in files: 92 for arg in args:
137 print(file) 93 files.append(arg)
138 94
139 if not makeFile(options.output, options.root_prefix, options.package_dir, 95 if not makeFile(options.output, options.root_prefix, files):
140 options.third_party_dir, options.rebase, files):
141 return -1 96 return -1
142 97
143 return 0 98 return 0
144 except Exception, inst: 99 except Exception, inst:
145 sys.stderr.write('create_resources.py exception\n') 100 sys.stderr.write('create_resources.py exception\n')
146 sys.stderr.write(str(inst)) 101 sys.stderr.write(str(inst))
147 sys.stderr.write('\n') 102 sys.stderr.write('\n')
148 return -1 103 return -1
149 104
150 if __name__ == '__main__': 105 if __name__ == '__main__':
151 sys.exit(main(sys.argv)) 106 sys.exit(main(sys.argv))
OLDNEW
« runtime/bin/vmservice/client/out/web/index.html ('K') | « runtime/bin/vmservice_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698