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

Side by Side Diff: grit_info.py

Issue 11085048: Allow to specify resources_ids file in grit_info.py. (Closed) Base URL: http://git.chromium.org/external/grit-i18n.git@master
Patch Set: Created 8 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
« no previous file with comments | « no previous file | 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 sys 12 import sys
13 13
14 from grit import grd_reader 14 from grit import grd_reader
15 from grit import util 15 from grit import util
16 16
17 class WrongNumberOfArguments(Exception): 17 class WrongNumberOfArguments(Exception):
18 pass 18 pass
19 19
20 20
21 def Outputs(filename, defines): 21 def Outputs(filename, defines, ids_file):
22 # TODO(joi@chromium.org): The first_ids_file can now be specified
23 # via an attribute on the <grit> node. Once a change lands in
24 # WebKit to use this attribute, we can stop specifying the
25 # first_ids_file parameter here and instead specify it in all grd
26 # files. For now, since Chrome is the only user of grit_info.py,
27 # this is fine.
28 grd = grd_reader.Parse( 22 grd = grd_reader.Parse(
29 filename, defines=defines, tags_to_ignore=set(['messages']), 23 filename, defines=defines, tags_to_ignore=set(['messages']),
30 first_ids_file='GRIT_DIR/../gritsettings/resource_ids') 24 first_ids_file=ids_file)
31 25
32 target = [] 26 target = []
33 lang_folders = {} 27 lang_folders = {}
34 # Add all explicitly-specified output files 28 # Add all explicitly-specified output files
35 for output in grd.GetOutputFiles(): 29 for output in grd.GetOutputFiles():
36 path = output.GetFilename() 30 path = output.GetFilename()
37 target.append(path) 31 target.append(path)
38 32
39 if path.endswith('.h'): 33 if path.endswith('.h'):
40 path, filename = os.path.split(path) 34 path, filename = os.path.split(path)
(...skipping 19 matching lines...) Expand all
60 def GritSourceFiles(): 54 def GritSourceFiles():
61 files = [] 55 files = []
62 grit_root_dir = os.path.relpath(os.path.dirname(__file__), os.getcwd()) 56 grit_root_dir = os.path.relpath(os.path.dirname(__file__), os.getcwd())
63 for root, dirs, filenames in os.walk(grit_root_dir): 57 for root, dirs, filenames in os.walk(grit_root_dir):
64 grit_src = [os.path.join(root, f) for f in filenames 58 grit_src = [os.path.join(root, f) for f in filenames
65 if f.endswith('.py')] 59 if f.endswith('.py')]
66 files.extend(grit_src) 60 files.extend(grit_src)
67 return files 61 return files
68 62
69 63
70 def Inputs(filename, defines): 64 def Inputs(filename, defines, ids_file):
71 # TODO(joi@chromium.org): The first_ids_file can now be specified
72 # via an attribute on the <grit> node. Once a change lands in
73 # WebKit to use this attribute, we can stop specifying the
74 # first_ids_file parameter here and instead specify it in all grd
75 # files. For now, since Chrome is the only user of grit_info.py,
76 # this is fine.
77 grd = grd_reader.Parse( 65 grd = grd_reader.Parse(
78 filename, debug=False, defines=defines, tags_to_ignore=set(['messages']), 66 filename, debug=False, defines=defines, tags_to_ignore=set(['messages']),
79 first_ids_file='GRIT_DIR/../gritsettings/resource_ids') 67 first_ids_file=ids_file)
80 files = set() 68 files = set()
81 contexts = set(output.GetContext() for output in grd.GetOutputFiles()) 69 contexts = set(output.GetContext() for output in grd.GetOutputFiles())
82 for node in grd: 70 for node in grd:
83 if (node.name == 'structure' or node.name == 'skeleton' or 71 if (node.name == 'structure' or node.name == 'skeleton' or
84 (node.name == 'file' and node.parent and 72 (node.name == 'file' and node.parent and
85 node.parent.name == 'translations')): 73 node.parent.name == 'translations')):
86 # TODO(benrg): This is an awful hack. Do dependencies right. 74 # TODO(benrg): This is an awful hack. Do dependencies right.
87 for context in contexts: 75 for context in contexts:
88 grd.SetOutputContext(context) 76 grd.SetOutputContext(context)
89 if node.SatisfiesOutputCondition(): 77 if node.SatisfiesOutputCondition():
(...skipping 15 matching lines...) Expand all
105 files.update(node.GetHtmlResourceFilenames()) 93 files.update(node.GetHtmlResourceFilenames())
106 elif node.name == 'part': 94 elif node.name == 'part':
107 if node.SatisfiesOutputCondition(): 95 if node.SatisfiesOutputCondition():
108 files.add(grd.ToRealPath(node.GetInputPath())) 96 files.add(grd.ToRealPath(node.GetInputPath()))
109 97
110 cwd = os.getcwd() 98 cwd = os.getcwd()
111 return [os.path.relpath(f, cwd) for f in sorted(files)] 99 return [os.path.relpath(f, cwd) for f in sorted(files)]
112 100
113 101
114 def PrintUsage(): 102 def PrintUsage():
115 print 'USAGE: ./grit_info.py --inputs [-D foo] <grd-file>' 103 print 'USAGE: ./grit_info.py --inputs [-D foo] [-f resource_ids] <grd-file>'
116 print ' ./grit_info.py --outputs [-D foo] <out-prefix> <grd-file>' 104 print (' ./grit_info.py --outputs [-D foo] [-f resource_ids] ' +
105 '<out-prefix> <grd-file>')
117 106
118 107
119 def DoMain(argv): 108 def DoMain(argv):
120 parser = optparse.OptionParser() 109 parser = optparse.OptionParser()
121 parser.add_option("--inputs", action="store_true", dest="inputs") 110 parser.add_option("--inputs", action="store_true", dest="inputs")
122 parser.add_option("--outputs", action="store_true", dest="outputs") 111 parser.add_option("--outputs", action="store_true", dest="outputs")
123 parser.add_option("-D", action="append", dest="defines", default=[]) 112 parser.add_option("-D", action="append", dest="defines", default=[])
124 # grit build also supports '-E KEY=VALUE', support that to share command 113 # grit build also supports '-E KEY=VALUE', support that to share command
125 # line flags. 114 # line flags.
126 parser.add_option("-E", action="append", dest="build_env", default=[]) 115 parser.add_option("-E", action="append", dest="build_env", default=[])
127 parser.add_option("-w", action="append", dest="whitelist_files", default=[]) 116 parser.add_option("-w", action="append", dest="whitelist_files", default=[])
117 parser.add_option("-f", dest="ids_file",
118 default="GRIT_DIR/../gritsettings/resource_ids")
128 119
129 options, args = parser.parse_args(argv) 120 options, args = parser.parse_args(argv)
130 121
131 defines = {} 122 defines = {}
132 for define in options.defines: 123 for define in options.defines:
133 name, val = util.ParseDefine(define) 124 name, val = util.ParseDefine(define)
134 defines[name] = val 125 defines[name] = val
135 126
136 if options.inputs: 127 if options.inputs:
137 if len(args) > 1: 128 if len(args) > 1:
138 raise WrongNumberOfArguments("Expected 0 or 1 arguments for --inputs.") 129 raise WrongNumberOfArguments("Expected 0 or 1 arguments for --inputs.")
139 130
140 inputs = [] 131 inputs = []
141 if len(args) == 1: 132 if len(args) == 1:
142 filename = args[0] 133 filename = args[0]
143 inputs = Inputs(filename, defines) 134 inputs = Inputs(filename, defines, options.ids_file)
144 135
145 # Add in the grit source files. If one of these change, we want to re-run 136 # Add in the grit source files. If one of these change, we want to re-run
146 # grit. 137 # grit.
147 inputs.extend(GritSourceFiles()) 138 inputs.extend(GritSourceFiles())
148 inputs = [f.replace('\\', '/') for f in inputs] 139 inputs = [f.replace('\\', '/') for f in inputs]
149 140
150 if len(args) == 1: 141 if len(args) == 1:
151 # Include grd file as second input (works around gyp expecting it). 142 # Include grd file as second input (works around gyp expecting it).
152 inputs.insert(1, args[0]) 143 inputs.insert(1, args[0])
153 if options.whitelist_files: 144 if options.whitelist_files:
154 inputs.extend(options.whitelist_files) 145 inputs.extend(options.whitelist_files)
155 return '\n'.join(inputs) 146 return '\n'.join(inputs)
156 elif options.outputs: 147 elif options.outputs:
157 if len(args) != 2: 148 if len(args) != 2:
158 raise WrongNumberOfArguments( 149 raise WrongNumberOfArguments(
159 "Expected exactly 2 arguments for --outputs.") 150 "Expected exactly 2 arguments for --outputs.")
160 151
161 prefix, filename = args 152 prefix, filename = args
162 outputs = [posixpath.join(prefix, f) for f in Outputs(filename, defines)] 153 outputs = [posixpath.join(prefix, f)
154 for f in Outputs(filename, defines, options.ids_file)]
163 return '\n'.join(outputs) 155 return '\n'.join(outputs)
164 else: 156 else:
165 raise WrongNumberOfArguments("Expected --inputs or --outputs.") 157 raise WrongNumberOfArguments("Expected --inputs or --outputs.")
166 158
167 159
168 def main(argv): 160 def main(argv):
169 if sys.version_info < (2, 6): 161 if sys.version_info < (2, 6):
170 print "GRIT requires Python 2.6 or later." 162 print "GRIT requires Python 2.6 or later."
171 return 1 163 return 1
172 164
173 try: 165 try:
174 result = DoMain(argv[1:]) 166 result = DoMain(argv[1:])
175 except WrongNumberOfArguments, e: 167 except WrongNumberOfArguments, e:
176 PrintUsage() 168 PrintUsage()
177 print e 169 print e
178 return 1 170 return 1
179 print result 171 print result
180 return 0 172 return 0
181 173
182 174
183 if __name__ == '__main__': 175 if __name__ == '__main__':
184 sys.exit(main(sys.argv)) 176 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698