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

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: fix .grd, add testOutputAllResourceDefinesFalse 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 -t PLATFORM Specifies the platform the build is targeting; defaults 97 -t PLATFORM Specifies the platform the build is targeting; defaults
98 to the value of sys.platform. The value provided via this 98 to the value of sys.platform. The value provided via this
99 flag should match what sys.platform would report for your 99 flag should match what sys.platform would report for your
100 target platform; see grit.node.base.EvaluateCondition. 100 target platform; see grit.node.base.EvaluateCondition.
101 101
102 -h HEADERFORMAT Custom format string to use for generating rc header files. 102 -h HEADERFORMAT Custom format string to use for generating rc header files.
103 The string should have two placeholders: {textual_id} 103 The string should have two placeholders: {textual_id}
104 and {numeric_id}. E.g. "#define {textual_id} {numeric_id}" 104 and {numeric_id}. E.g. "#define {textual_id} {numeric_id}"
105 Otherwise it will use the default "#define SYMBOL 1234" 105 Otherwise it will use the default "#define SYMBOL 1234"
106 106
107 --output-all-resource-defines
108 --no-output-all-resource-defines If specified, overrides the value of the
109 output_all_resource_defines attribute of the root <grit>
110 element of the input .grd file.
111
107 Conditional inclusion of resources only affects the output of files which 112 Conditional inclusion of resources only affects the output of files which
108 control which resources get linked into a binary, e.g. it affects .rc files 113 control which resources get linked into a binary, e.g. it affects .rc files
109 meant for compilation but it does not affect resource header files (that define 114 meant for compilation but it does not affect resource header files (that define
110 IDs). This helps ensure that values of IDs stay the same, that all messages 115 IDs). This helps ensure that values of IDs stay the same, that all messages
111 are exported to translation interchange files (e.g. XMB files), etc. 116 are exported to translation interchange files (e.g. XMB files), etc.
112 ''' 117 '''
113 118
114 def ShortDescription(self): 119 def ShortDescription(self):
115 return 'A tool that builds RC files for compilation.' 120 return 'A tool that builds RC files for compilation.'
116 121
117 def Run(self, opts, args): 122 def Run(self, opts, args):
118 self.output_directory = '.' 123 self.output_directory = '.'
119 first_ids_file = None 124 first_ids_file = None
120 whitelist_filenames = [] 125 whitelist_filenames = []
121 assert_output_files = [] 126 assert_output_files = []
122 target_platform = None 127 target_platform = None
123 depfile = None 128 depfile = None
124 depdir = None 129 depdir = None
125 rc_header_format = None 130 rc_header_format = None
131 output_all_resource_defines = None
126 (own_opts, args) = getopt.getopt(args, 'a:o:D:E:f:w:t:h:', 132 (own_opts, args) = getopt.getopt(args, 'a:o:D:E:f:w:t:h:',
127 ('depdir=','depfile=','assert-file-list=')) 133 ('depdir=','depfile=','assert-file-list=',
134 'output-all-resource-defines',
135 'no-output-all-resource-defines',))
128 for (key, val) in own_opts: 136 for (key, val) in own_opts:
129 if key == '-a': 137 if key == '-a':
130 assert_output_files.append(val) 138 assert_output_files.append(val)
131 elif key == '--assert-file-list': 139 elif key == '--assert-file-list':
132 with open(val) as f: 140 with open(val) as f:
133 assert_output_files += f.read().splitlines() 141 assert_output_files += f.read().splitlines()
134 elif key == '-o': 142 elif key == '-o':
135 self.output_directory = val 143 self.output_directory = val
136 elif key == '-D': 144 elif key == '-D':
137 name, val = util.ParseDefine(val) 145 name, val = util.ParseDefine(val)
138 self.defines[name] = val 146 self.defines[name] = val
139 elif key == '-E': 147 elif key == '-E':
140 (env_name, env_value) = val.split('=', 1) 148 (env_name, env_value) = val.split('=', 1)
141 os.environ[env_name] = env_value 149 os.environ[env_name] = env_value
142 elif key == '-f': 150 elif key == '-f':
143 # TODO(joi@chromium.org): Remove this override once change 151 # TODO(joi@chromium.org): Remove this override once change
144 # lands in WebKit.grd to specify the first_ids_file in the 152 # lands in WebKit.grd to specify the first_ids_file in the
145 # .grd itself. 153 # .grd itself.
146 first_ids_file = val 154 first_ids_file = val
147 elif key == '-w': 155 elif key == '-w':
148 whitelist_filenames.append(val) 156 whitelist_filenames.append(val)
157 elif key == '--output-all-resource-defines':
158 output_all_resource_defines = True
159 elif key == '--no-output-all-resource-defines':
160 output_all_resource_defines = False
149 elif key == '-t': 161 elif key == '-t':
150 target_platform = val 162 target_platform = val
151 elif key == '-h': 163 elif key == '-h':
152 rc_header_format = val 164 rc_header_format = val
153 elif key == '--depdir': 165 elif key == '--depdir':
154 depdir = val 166 depdir = val
155 elif key == '--depfile': 167 elif key == '--depfile':
156 depfile = val 168 depfile = val
157 169
158 if len(args): 170 if len(args):
(...skipping 12 matching lines...) Expand all
171 for whitelist_filename in whitelist_filenames: 183 for whitelist_filename in whitelist_filenames:
172 self.VerboseOut('Using whitelist: %s\n' % whitelist_filename); 184 self.VerboseOut('Using whitelist: %s\n' % whitelist_filename);
173 whitelist_contents = util.ReadFile(whitelist_filename, util.RAW_TEXT) 185 whitelist_contents = util.ReadFile(whitelist_filename, util.RAW_TEXT)
174 self.whitelist_names.update(whitelist_contents.strip().split('\n')) 186 self.whitelist_names.update(whitelist_contents.strip().split('\n'))
175 187
176 self.res = grd_reader.Parse(opts.input, 188 self.res = grd_reader.Parse(opts.input,
177 debug=opts.extra_verbose, 189 debug=opts.extra_verbose,
178 first_ids_file=first_ids_file, 190 first_ids_file=first_ids_file,
179 defines=self.defines, 191 defines=self.defines,
180 target_platform=target_platform) 192 target_platform=target_platform)
193
194 # If the output_all_resource_defines option is specified, override the value
195 # found in the grd file.
196 if output_all_resource_defines is not None:
197 self.res.SetShouldOutputAllResourceDefines(output_all_resource_defines)
198
181 # Set an output context so that conditionals can use defines during the 199 # 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 200 # gathering stage; we use a dummy language here since we are not outputting
183 # a specific language. 201 # a specific language.
184 self.res.SetOutputLanguage('en') 202 self.res.SetOutputLanguage('en')
185 if rc_header_format: 203 if rc_header_format:
186 self.res.AssignRcHeaderFormat(rc_header_format) 204 self.res.AssignRcHeaderFormat(rc_header_format)
187 self.res.RunGatherers() 205 self.res.RunGatherers()
188 self.Process() 206 self.Process()
189 207
190 if assert_output_files: 208 if assert_output_files:
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 self.MakeDirectoriesTo(depfile) 445 self.MakeDirectoriesTo(depfile)
428 outfile = self.fo_create(depfile, 'wb') 446 outfile = self.fo_create(depfile, 'wb')
429 outfile.writelines(depfile_contents) 447 outfile.writelines(depfile_contents)
430 448
431 @staticmethod 449 @staticmethod
432 def MakeDirectoriesTo(file): 450 def MakeDirectoriesTo(file):
433 '''Creates directories necessary to contain |file|.''' 451 '''Creates directories necessary to contain |file|.'''
434 dir = os.path.split(file)[0] 452 dir = os.path.split(file)[0]
435 if not os.path.exists(dir): 453 if not os.path.exists(dir):
436 os.makedirs(dir) 454 os.makedirs(dir)
OLDNEW
« no previous file with comments | « grit/testdata/whitelist_resources.grd ('k') | grit/tool/build_unittest.py » ('j') | grit_info.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698