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

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

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