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

Side by Side Diff: grit_info.py

Issue 9802029: Make first_ids_file an optional attribute of the .grd file. (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk/
Patch Set: Created 8 years, 8 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
« grit/tool/build.py ('K') | « grit/tool/build.py ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 '''Tool to determine inputs and outputs of a grit file. 6 '''Tool to determine inputs and outputs of a grit file.
7 ''' 7 '''
8 8
9 import optparse 9 import optparse
10 import os 10 import os
11 import posixpath 11 import posixpath
12 import types 12 import types
13 import sys 13 import sys
14 14
15 from grit import grd_reader 15 from grit import grd_reader
16 from grit import util 16 from grit import util
17 17
18 class WrongNumberOfArguments(Exception): 18 class WrongNumberOfArguments(Exception):
19 pass 19 pass
20 20
21 21
22 def Outputs(filename, defines): 22 def Outputs(filename, defines):
23 # TODO(joi@chromium.org): The first_ids_file can now be specified
24 # via an attribute on the <grit> node. Once a change lands in
25 # WebKit to use this attribute, we can stop specifying the
26 # first_ids_file parameter here and instead specify it in all grd
27 # files. For now, since Chrome is the only user of grit_info.py,
28 # this is fine.
23 grd = grd_reader.Parse( 29 grd = grd_reader.Parse(
24 filename, defines=defines, tags_to_ignore=set(['messages'])) 30 filename, defines=defines, tags_to_ignore=set(['messages']),
31 first_ids_file='GRIT_DIR/../gritsettings/resource_ids')
25 32
26 target = [] 33 target = []
27 lang_folders = {} 34 lang_folders = {}
28 # Add all explicitly-specified output files 35 # Add all explicitly-specified output files
29 for output in grd.GetOutputFiles(): 36 for output in grd.GetOutputFiles():
30 path = output.GetFilename() 37 path = output.GetFilename()
31 target.append(path) 38 target.append(path)
32 39
33 if path.endswith('.h'): 40 if path.endswith('.h'):
34 path, filename = os.path.split(path) 41 path, filename = os.path.split(path)
(...skipping 16 matching lines...) Expand all
51 return [t.replace('\\', '/') for t in target] 58 return [t.replace('\\', '/') for t in target]
52 59
53 60
54 def GritSourceFiles(): 61 def GritSourceFiles():
55 files = [] 62 files = []
56 grit_root_dir = os.path.relpath(os.path.dirname(__file__), os.getcwd()) 63 grit_root_dir = os.path.relpath(os.path.dirname(__file__), os.getcwd())
57 for root, dirs, filenames in os.walk(grit_root_dir): 64 for root, dirs, filenames in os.walk(grit_root_dir):
58 grit_src = [os.path.join(root, f) for f in filenames 65 grit_src = [os.path.join(root, f) for f in filenames
59 if f.endswith('.py')] 66 if f.endswith('.py')]
60 files.extend(grit_src) 67 files.extend(grit_src)
61 # TODO(joi@chromium.org): Once we switch to specifying the
62 # resource_ids file via a .grd attribute, it should be considered an
63 # input of grit and this bit should no longer be necessary.
64 default_resource_ids = os.path.relpath(
65 os.path.join(grit_root_dir, '..', 'gritsettings', 'resource_ids'),
66 os.getcwd())
67 if os.path.exists(default_resource_ids):
68 files.append(default_resource_ids)
69 return files 68 return files
70 69
71 70
72 def Inputs(filename, defines): 71 def Inputs(filename, defines):
72 # TODO(joi@chromium.org): The first_ids_file can now be specified
73 # via an attribute on the <grit> node. Once a change lands in
74 # WebKit to use this attribute, we can stop specifying the
75 # first_ids_file parameter here and instead specify it in all grd
76 # files. For now, since Chrome is the only user of grit_info.py,
77 # this is fine.
73 grd = grd_reader.Parse( 78 grd = grd_reader.Parse(
74 filename, debug=False, defines=defines, tags_to_ignore=set(['messages'])) 79 filename, debug=False, defines=defines, tags_to_ignore=set(['messages']),
80 first_ids_file='GRIT_DIR/../gritsettings/resource_ids')
75 files = [] 81 files = []
76 for node in grd: 82 for node in grd:
77 if (node.name == 'structure' or node.name == 'skeleton' or 83 if (node.name == 'structure' or node.name == 'skeleton' or
78 (node.name == 'file' and node.parent and 84 (node.name == 'file' and node.parent and
79 node.parent.name == 'translations')): 85 node.parent.name == 'translations')):
80 files.append(node.GetFilePath()) 86 files.append(node.GetFilePath())
87 elif node.name == 'grit':
88 first_ids_file = node.GetFirstIdsFile()
89 if first_ids_file:
90 files.append(first_ids_file)
81 elif node.name == 'include': 91 elif node.name == 'include':
82 # Only include files that we actually plan on using. 92 # Only include files that we actually plan on using.
83 if node.SatisfiesOutputCondition(): 93 if node.SatisfiesOutputCondition():
84 files.append(node.FilenameToOpen()) 94 files.append(node.FilenameToOpen())
85 # If it's a flattened node, grab inlined resources too. 95 # If it's a flattened node, grab inlined resources too.
86 if node.attrs['flattenhtml'] == 'true': 96 if node.attrs['flattenhtml'] == 'true':
87 files.extend(node.GetHtmlResourceFilenames()) 97 files.extend(node.GetHtmlResourceFilenames())
88 98
89 return files 99 return files
90 100
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 except WrongNumberOfArguments, e: 161 except WrongNumberOfArguments, e:
152 PrintUsage() 162 PrintUsage()
153 print e 163 print e
154 return 1 164 return 1
155 print result 165 print result
156 return 0 166 return 0
157 167
158 168
159 if __name__ == '__main__': 169 if __name__ == '__main__':
160 sys.exit(main(sys.argv)) 170 sys.exit(main(sys.argv))
OLDNEW
« grit/tool/build.py ('K') | « grit/tool/build.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698