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

Side by Side Diff: grit/tool/build.py

Issue 691873002: Add support to override output_all_resource_defines from command line. (Closed) Base URL: https://chromium.googlesource.com/external/grit-i18n.git@master
Patch Set: Created 6 years, 1 month 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
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 '''The 'grit build' tool along with integration for this tool with the 6 '''The 'grit build' tool along with integration for this tool with the
7 SCons build system. 7 SCons build system.
8 ''' 8 '''
9 9
10 import filecmp 10 import filecmp
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 module = sys.modules[modulename] 48 module = sys.modules[modulename]
49 try: 49 try:
50 return module.Format 50 return module.Format
51 except AttributeError: 51 except AttributeError:
52 return module.GetFormatter(type) 52 return module.GetFormatter(type)
53 53
54 54
55 class RcBuilder(interface.Tool): 55 class RcBuilder(interface.Tool):
56 '''A tool that builds RC files and resource header files for compilation. 56 '''A tool that builds RC files and resource header files for compilation.
57 57
58 Usage: grit build [-o OUTPUTDIR] [-D NAME[=VAL]]* 58 Usage: grit build [-o OUTPUTDIR] [-D NAME[=VAL]]*
newt (away) 2014/10/30 20:16:20 update this usage comment as well
lliabraa 2014/10/31 11:33:13 Done.
59 59
60 All output options for this tool are specified in the input file (see 60 All output options for this tool are specified in the input file (see
61 'grit help' for details on how to specify the input file - it is a global 61 'grit help' for details on how to specify the input file - it is a global
62 option). 62 option).
63 63
64 Options: 64 Options:
65 65
66 -a FILE Assert that the given file is an output. There can be 66 -a FILE Assert that the given file is an output. There can be
67 multiple "-a" flags listed for multiple outputs. If a "-a" 67 multiple "-a" flags listed for multiple outputs. If a "-a"
68 or "--assert-file-list" argument is present, then the list 68 or "--assert-file-list" argument is present, then the list
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 116
117 def Run(self, opts, args): 117 def Run(self, opts, args):
118 self.output_directory = '.' 118 self.output_directory = '.'
119 first_ids_file = None 119 first_ids_file = None
120 whitelist_filenames = [] 120 whitelist_filenames = []
121 assert_output_files = [] 121 assert_output_files = []
122 target_platform = None 122 target_platform = None
123 depfile = None 123 depfile = None
124 depdir = None 124 depdir = None
125 rc_header_format = None 125 rc_header_format = None
126 output_all_resource_defines = None
126 (own_opts, args) = getopt.getopt(args, 'a:o:D:E:f:w:t:h:', 127 (own_opts, args) = getopt.getopt(args, 'a:o:D:E:f:w:t:h:',
127 ('depdir=','depfile=','assert-file-list=')) 128 ('depdir=','depfile=','assert-file-list=',
129 'output-all-resource-defines',
newt (away) 2014/10/30 20:16:20 Alternatively, this could accept an argument, e.g.
lliabraa 2014/10/31 11:33:13 I think this is a little more explicit because it
130 'nooutput-all-resource-defines',))
128 for (key, val) in own_opts: 131 for (key, val) in own_opts:
129 if key == '-a': 132 if key == '-a':
130 assert_output_files.append(val) 133 assert_output_files.append(val)
131 elif key == '--assert-file-list': 134 elif key == '--assert-file-list':
132 with open(val) as f: 135 with open(val) as f:
133 assert_output_files += f.read().splitlines() 136 assert_output_files += f.read().splitlines()
134 elif key == '-o': 137 elif key == '-o':
135 self.output_directory = val 138 self.output_directory = val
136 elif key == '-D': 139 elif key == '-D':
137 name, val = util.ParseDefine(val) 140 name, val = util.ParseDefine(val)
138 self.defines[name] = val 141 self.defines[name] = val
139 elif key == '-E': 142 elif key == '-E':
140 (env_name, env_value) = val.split('=', 1) 143 (env_name, env_value) = val.split('=', 1)
141 os.environ[env_name] = env_value 144 os.environ[env_name] = env_value
142 elif key == '-f': 145 elif key == '-f':
143 # TODO(joi@chromium.org): Remove this override once change 146 # TODO(joi@chromium.org): Remove this override once change
144 # lands in WebKit.grd to specify the first_ids_file in the 147 # lands in WebKit.grd to specify the first_ids_file in the
145 # .grd itself. 148 # .grd itself.
146 first_ids_file = val 149 first_ids_file = val
147 elif key == '-w': 150 elif key == '-w':
148 whitelist_filenames.append(val) 151 whitelist_filenames.append(val)
152 elif key == '--output-all-resource-defines':
153 output_all_resource_defines = True
154 elif key == '--nooutput-all-resource-defines':
155 output_all_resource_defines = False
149 elif key == '-t': 156 elif key == '-t':
150 target_platform = val 157 target_platform = val
151 elif key == '-h': 158 elif key == '-h':
152 rc_header_format = val 159 rc_header_format = val
153 elif key == '--depdir': 160 elif key == '--depdir':
154 depdir = val 161 depdir = val
155 elif key == '--depfile': 162 elif key == '--depfile':
156 depfile = val 163 depfile = val
157 164
158 if len(args): 165 if len(args):
(...skipping 12 matching lines...) Expand all
171 for whitelist_filename in whitelist_filenames: 178 for whitelist_filename in whitelist_filenames:
172 self.VerboseOut('Using whitelist: %s\n' % whitelist_filename); 179 self.VerboseOut('Using whitelist: %s\n' % whitelist_filename);
173 whitelist_contents = util.ReadFile(whitelist_filename, util.RAW_TEXT) 180 whitelist_contents = util.ReadFile(whitelist_filename, util.RAW_TEXT)
174 self.whitelist_names.update(whitelist_contents.strip().split('\n')) 181 self.whitelist_names.update(whitelist_contents.strip().split('\n'))
175 182
176 self.res = grd_reader.Parse(opts.input, 183 self.res = grd_reader.Parse(opts.input,
177 debug=opts.extra_verbose, 184 debug=opts.extra_verbose,
178 first_ids_file=first_ids_file, 185 first_ids_file=first_ids_file,
179 defines=self.defines, 186 defines=self.defines,
180 target_platform=target_platform) 187 target_platform=target_platform)
188
189 # If the output_all_resource_defines option is specified, override the value
190 # found in the grd file.
191 if output_all_resource_defines is not None:
192 self.res.SetShouldOutputAllResourceDefines(output_all_resource_defines)
193
181 # Set an output context so that conditionals can use defines during the 194 # Set an output context so that conditionals can use defines during the
182 # gathering stage; we use a dummy language here since we are not outputting 195 # gathering stage; we use a dummy language here since we are not outputting
183 # a specific language. 196 # a specific language.
184 self.res.SetOutputLanguage('en') 197 self.res.SetOutputLanguage('en')
185 if rc_header_format: 198 if rc_header_format:
186 self.res.AssignRcHeaderFormat(rc_header_format) 199 self.res.AssignRcHeaderFormat(rc_header_format)
187 self.res.RunGatherers() 200 self.res.RunGatherers()
188 self.Process() 201 self.Process()
189 202
190 if assert_output_files: 203 if assert_output_files:
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 self.MakeDirectoriesTo(depfile) 438 self.MakeDirectoriesTo(depfile)
426 outfile = self.fo_create(depfile, 'wb') 439 outfile = self.fo_create(depfile, 'wb')
427 outfile.writelines(depfile_contents) 440 outfile.writelines(depfile_contents)
428 441
429 @staticmethod 442 @staticmethod
430 def MakeDirectoriesTo(file): 443 def MakeDirectoriesTo(file):
431 '''Creates directories necessary to contain |file|.''' 444 '''Creates directories necessary to contain |file|.'''
432 dir = os.path.split(file)[0] 445 dir = os.path.split(file)[0]
433 if not os.path.exists(dir): 446 if not os.path.exists(dir):
434 os.makedirs(dir) 447 os.makedirs(dir)
OLDNEW
« no previous file with comments | « grit/node/misc.py ('k') | grit/tool/build_unittest.py » ('j') | grit/tool/build_unittest.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698