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

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

Issue 837723004: Build Observatory as part of runtime (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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
« no previous file with comments | « runtime/observatory/web/main.dart ('k') | tools/build.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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, input_files, table_name): 16 def makeResources(root_dir, client_dir, input_files, table_name):
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 client_dir and resource_file.startswith(client_dir):
25 resource_file_name = resource_file[ len(client_dir) : ]
24 else: 26 else:
25 resource_file_name = resource_file 27 resource_file_name = resource_file
26 resource_url = '/%s' % resource_file_name 28 resource_url = '/%s' % resource_file_name
27 result += '// %s\n' % resource_file 29 result += '// %s\n' % resource_file
28 result += 'const char ' 30 result += 'const char '
29 resource_name = re.sub(r'(/|\.|-|\\)', '_', resource_file_name) + '_' 31 resource_name = re.sub(r'(/|\.|-|\\)', '_', resource_file_name) + '_'
30 result += resource_name 32 result += resource_name
31 result += '[] = {\n ' 33 result += '[] = {\n '
32 fileHandle = open(resource_file, 'rb') 34 fileHandle = open(resource_file, 'rb')
33 lineCounter = 0 35 lineCounter = 0
(...skipping 13 matching lines...) Expand all
47 # Write the resource table. 49 # Write the resource table.
48 result += 'ResourcesEntry __%s_resources_[] = ' % table_name 50 result += 'ResourcesEntry __%s_resources_[] = ' % table_name
49 result += '{\n' 51 result += '{\n'
50 for res in resources: 52 for res in resources:
51 result += ' { "%s", %s, %d },\n' % res 53 result += ' { "%s", %s, %d },\n' % res
52 result += ' { 0, 0, 0 },\n' 54 result += ' { 0, 0, 0 },\n'
53 result += '};\n\n' 55 result += '};\n\n'
54 return result 56 return result
55 57
56 58
57 def makeFile(output_file, root_dir, input_files, outer_namespace, 59 def makeFile(output_file, root_dir, client_dir, input_files, outer_namespace,
58 inner_namespace, table_name): 60 inner_namespace, table_name):
59 cc_text = ''' 61 cc_text = '''
60 // Copyright (c) %d, the Dart project authors. Please see the AUTHORS file 62 // Copyright (c) %d, the Dart project authors. Please see the AUTHORS file
61 // for details. All rights reserved. Use of this source code is governed by a 63 // for details. All rights reserved. Use of this source code is governed by a
62 // BSD-style license that can be found in the LICENSE file. 64 // BSD-style license that can be found in the LICENSE file.
63 65
64 ''' % date.today().year 66 ''' % date.today().year
65 cc_text += 'namespace %s {\n' % outer_namespace 67 cc_text += 'namespace %s {\n' % outer_namespace
66 if inner_namespace != None: 68 if inner_namespace != None:
67 cc_text += 'namespace %s {\n' % inner_namespace 69 cc_text += 'namespace %s {\n' % inner_namespace
68 cc_text += ''' 70 cc_text += '''
69 struct ResourcesEntry { 71 struct ResourcesEntry {
70 const char* path_; 72 const char* path_;
71 const char* resource_; 73 const char* resource_;
72 int length_; 74 int length_;
73 }; 75 };
74 76
75 ''' 77 '''
76 cc_text += makeResources(root_dir, input_files, table_name) 78 cc_text += makeResources(root_dir, client_dir, input_files, table_name)
77 cc_text += '\n' 79 cc_text += '\n'
78 if inner_namespace != None: 80 if inner_namespace != None:
79 cc_text += '} // namespace %s\n' % inner_namespace 81 cc_text += '} // namespace %s\n' % inner_namespace
80 cc_text += '} // namespace %s\n' % outer_namespace 82 cc_text += '} // namespace %s\n' % outer_namespace
81 open(output_file, 'w').write(cc_text) 83 open(output_file, 'w').write(cc_text)
82 return True 84 return True
83 85
84 86
85 def main(args): 87 def main(args):
86 try: 88 try:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 if (os.path.isdir(src_path)): 130 if (os.path.isdir(src_path)):
129 continue 131 continue
130 # Skip devtools version 132 # Skip devtools version
131 if (src_path.find("index_devtools") != -1): 133 if (src_path.find("index_devtools") != -1):
132 continue 134 continue
133 files.append(src_path) 135 files.append(src_path)
134 136
135 for arg in args: 137 for arg in args:
136 files.append(arg) 138 files.append(arg)
137 139
138 if not makeFile(options.output, options.root_prefix, files, 140 if not makeFile(options.output, options.root_prefix, options.client_root,
139 options.outer_namespace, options.inner_namespace, 141 files, options.outer_namespace, options.inner_namespace,
140 options.table_name): 142 options.table_name):
141 return -1 143 return -1
142 144
143 return 0 145 return 0
144 except Exception, inst: 146 except Exception, inst:
145 sys.stderr.write('create_resources.py exception\n') 147 sys.stderr.write('create_resources.py exception\n')
146 sys.stderr.write(str(inst)) 148 sys.stderr.write(str(inst))
147 sys.stderr.write('\n') 149 sys.stderr.write('\n')
148 return -1 150 return -1
149 151
150 if __name__ == '__main__': 152 if __name__ == '__main__':
151 sys.exit(main(sys.argv)) 153 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « runtime/observatory/web/main.dart ('k') | tools/build.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698