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

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

Issue 2177963002: Reland of grit: Automatically replace ... with … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaseline Created 4 years, 4 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
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 codecs 10 import codecs
11 import filecmp 11 import filecmp
12 import getopt 12 import getopt
13 import os 13 import os
14 import shutil 14 import shutil
15 import sys 15 import sys
16 16
17 from grit import grd_reader 17 from grit import grd_reader
18 from grit import shortcuts
18 from grit import util 19 from grit import util
20 from grit.node import include
21 from grit.node import message
22 from grit.node import structure
19 from grit.tool import interface 23 from grit.tool import interface
20 from grit import shortcuts
21 24
22 25
23 # It would be cleaner to have each module register itself, but that would 26 # It would be cleaner to have each module register itself, but that would
24 # require importing all of them on every run of GRIT. 27 # require importing all of them on every run of GRIT.
25 '''Map from <output> node types to modules under grit.format.''' 28 '''Map from <output> node types to modules under grit.format.'''
26 _format_modules = { 29 _format_modules = {
27 'android': 'android_xml', 30 'android': 'android_xml',
28 'c_format': 'c_format', 31 'c_format': 'c_format',
29 'chrome_messages_json': 'chrome_messages_json', 32 'chrome_messages_json': 'chrome_messages_json',
30 'data_package': 'data_pack', 33 'data_package': 'data_pack',
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 first_ids_file = None 141 first_ids_file = None
139 whitelist_filenames = [] 142 whitelist_filenames = []
140 assert_output_files = [] 143 assert_output_files = []
141 target_platform = None 144 target_platform = None
142 depfile = None 145 depfile = None
143 depdir = None 146 depdir = None
144 rc_header_format = None 147 rc_header_format = None
145 output_all_resource_defines = None 148 output_all_resource_defines = None
146 write_only_new = False 149 write_only_new = False
147 depend_on_stamp = False 150 depend_on_stamp = False
151 replace_ellipsis = True
148 (own_opts, args) = getopt.getopt(args, 'a:o:D:E:f:w:t:h:', 152 (own_opts, args) = getopt.getopt(args, 'a:o:D:E:f:w:t:h:',
149 ('depdir=','depfile=','assert-file-list=', 153 ('depdir=','depfile=','assert-file-list=',
150 'output-all-resource-defines', 154 'output-all-resource-defines',
151 'no-output-all-resource-defines', 155 'no-output-all-resource-defines',
156 'no-replace-ellipsis',
152 'depend-on-stamp', 157 'depend-on-stamp',
153 'write-only-new=')) 158 'write-only-new='))
154 for (key, val) in own_opts: 159 for (key, val) in own_opts:
155 if key == '-a': 160 if key == '-a':
156 assert_output_files.append(val) 161 assert_output_files.append(val)
157 elif key == '--assert-file-list': 162 elif key == '--assert-file-list':
158 with open(val) as f: 163 with open(val) as f:
159 assert_output_files += f.read().splitlines() 164 assert_output_files += f.read().splitlines()
160 elif key == '-o': 165 elif key == '-o':
161 self.output_directory = val 166 self.output_directory = val
162 elif key == '-D': 167 elif key == '-D':
163 name, val = util.ParseDefine(val) 168 name, val = util.ParseDefine(val)
164 self.defines[name] = val 169 self.defines[name] = val
165 elif key == '-E': 170 elif key == '-E':
166 (env_name, env_value) = val.split('=', 1) 171 (env_name, env_value) = val.split('=', 1)
167 os.environ[env_name] = env_value 172 os.environ[env_name] = env_value
168 elif key == '-f': 173 elif key == '-f':
169 # TODO(joi@chromium.org): Remove this override once change 174 # TODO(joi@chromium.org): Remove this override once change
170 # lands in WebKit.grd to specify the first_ids_file in the 175 # lands in WebKit.grd to specify the first_ids_file in the
171 # .grd itself. 176 # .grd itself.
172 first_ids_file = val 177 first_ids_file = val
173 elif key == '-w': 178 elif key == '-w':
174 whitelist_filenames.append(val) 179 whitelist_filenames.append(val)
175 elif key == '--output-all-resource-defines': 180 elif key == '--output-all-resource-defines':
176 output_all_resource_defines = True 181 output_all_resource_defines = True
177 elif key == '--no-output-all-resource-defines': 182 elif key == '--no-output-all-resource-defines':
178 output_all_resource_defines = False 183 output_all_resource_defines = False
184 elif key == '--no-replace-ellipsis':
185 replace_ellipsis = False
179 elif key == '-t': 186 elif key == '-t':
180 target_platform = val 187 target_platform = val
181 elif key == '-h': 188 elif key == '-h':
182 rc_header_format = val 189 rc_header_format = val
183 elif key == '--depdir': 190 elif key == '--depdir':
184 depdir = val 191 depdir = val
185 elif key == '--depfile': 192 elif key == '--depfile':
186 depfile = val 193 depfile = val
187 elif key == '--write-only-new': 194 elif key == '--write-only-new':
188 write_only_new = val != '0' 195 write_only_new = val != '0'
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 if output_all_resource_defines is not None: 227 if output_all_resource_defines is not None:
221 self.res.SetShouldOutputAllResourceDefines(output_all_resource_defines) 228 self.res.SetShouldOutputAllResourceDefines(output_all_resource_defines)
222 229
223 # Set an output context so that conditionals can use defines during the 230 # Set an output context so that conditionals can use defines during the
224 # gathering stage; we use a dummy language here since we are not outputting 231 # gathering stage; we use a dummy language here since we are not outputting
225 # a specific language. 232 # a specific language.
226 self.res.SetOutputLanguage('en') 233 self.res.SetOutputLanguage('en')
227 if rc_header_format: 234 if rc_header_format:
228 self.res.AssignRcHeaderFormat(rc_header_format) 235 self.res.AssignRcHeaderFormat(rc_header_format)
229 self.res.RunGatherers() 236 self.res.RunGatherers()
237
238 # Replace ... with the single-character version. http://crbug.com/621772
239 if replace_ellipsis:
240 for node in self.res:
241 if isinstance(node, message.MessageNode):
242 node.SetReplaceEllipsis(True)
243
230 self.Process() 244 self.Process()
231 245
232 if assert_output_files: 246 if assert_output_files:
233 if not self.CheckAssertedOutputFiles(assert_output_files): 247 if not self.CheckAssertedOutputFiles(assert_output_files):
234 return 2 248 return 2
235 249
236 if depfile and depdir: 250 if depfile and depdir:
237 self.GenerateDepfile(depfile, depdir, first_ids_file, depend_on_stamp) 251 self.GenerateDepfile(depfile, depdir, first_ids_file, depend_on_stamp)
238 252
239 return 0 253 return 0
(...skipping 20 matching lines...) Expand all
260 # output. 274 # output.
261 self.whitelist_names = None 275 self.whitelist_names = None
262 276
263 # Whether to compare outputs to their old contents before writing. 277 # Whether to compare outputs to their old contents before writing.
264 self.write_only_new = False 278 self.write_only_new = False
265 279
266 @staticmethod 280 @staticmethod
267 def AddWhitelistTags(start_node, whitelist_names): 281 def AddWhitelistTags(start_node, whitelist_names):
268 # Walk the tree of nodes added attributes for the nodes that shouldn't 282 # Walk the tree of nodes added attributes for the nodes that shouldn't
269 # be written into the target files (skip markers). 283 # be written into the target files (skip markers).
270 from grit.node import include
271 from grit.node import message
272 from grit.node import structure
273 for node in start_node: 284 for node in start_node:
274 # Same trick data_pack.py uses to see what nodes actually result in 285 # Same trick data_pack.py uses to see what nodes actually result in
275 # real items. 286 # real items.
276 if (isinstance(node, include.IncludeNode) or 287 if (isinstance(node, include.IncludeNode) or
277 isinstance(node, message.MessageNode) or 288 isinstance(node, message.MessageNode) or
278 isinstance(node, structure.StructureNode)): 289 isinstance(node, structure.StructureNode)):
279 text_ids = node.GetTextualIds() 290 text_ids = node.GetTextualIds()
280 # Mark the item to be skipped if it wasn't in the whitelist. 291 # Mark the item to be skipped if it wasn't in the whitelist.
281 if text_ids and text_ids[0] not in whitelist_names: 292 if text_ids and text_ids[0] not in whitelist_names:
282 node.SetWhitelistMarkedAsSkip(True) 293 node.SetWhitelistMarkedAsSkip(True)
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 self.MakeDirectoriesTo(depfile) 501 self.MakeDirectoriesTo(depfile)
491 outfile = self.fo_create(depfile, 'w', encoding='utf-8') 502 outfile = self.fo_create(depfile, 'w', encoding='utf-8')
492 outfile.writelines(depfile_contents) 503 outfile.writelines(depfile_contents)
493 504
494 @staticmethod 505 @staticmethod
495 def MakeDirectoriesTo(file): 506 def MakeDirectoriesTo(file):
496 '''Creates directories necessary to contain |file|.''' 507 '''Creates directories necessary to contain |file|.'''
497 dir = os.path.split(file)[0] 508 dir = os.path.split(file)[0]
498 if not os.path.exists(dir): 509 if not os.path.exists(dir):
499 os.makedirs(dir) 510 os.makedirs(dir)
OLDNEW
« third_party/WebKit/LayoutTests/TestExpectations ('K') | « tools/grit/grit/node/message_unittest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698