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

Side by Side Diff: components/variations/service/generate_ui_string_overrider.py

Issue 1969243002: Fix regex to parse Variations UI override strings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/python 1 #!/usr/bin/python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 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 import argparse 6 import argparse
7 import collections 7 import collections
8 import hashlib 8 import hashlib
9 import operator 9 import operator
10 import os 10 import os
11 import re 11 import re
12 import sys 12 import sys
13 13
14 SCRIPT_NAME = "generate_ui_string_overrider.py" 14 SCRIPT_NAME = "generate_ui_string_overrider.py"
15
Raj 2016/05/12 01:40:27 The pragma format is defined in https://code.googl
16
17 # Regular expressions for parsing the #define macro format. Separate regular
18 # expressions are used for parsing lines with pragma (for builds with
19 # enable_resource_whitelist_generation flag) in windows and non-windows, and for
20 # lines without pragma,
rkaplow 2016/05/12 01:52:53 could you give samples for the cases here
Raj 2016/05/12 17:03:40 Done.
15 RESOURCE_EXTRACT_REGEX = re.compile('^#define (\S*) (\d*)$', re.MULTILINE) 21 RESOURCE_EXTRACT_REGEX = re.compile('^#define (\S*) (\d*)$', re.MULTILINE)
22 RESOURCE_EXTRACT_REGEX_PRAGMA = re.compile(
23 '^#define (\S*) _Pragma\("whitelisted_resource_\d*"\) (\d*)$',
Alexei Svitkine (slow) 2016/05/12 14:40:41 Looks like these are defined here: https://code.g
Raj 2016/05/12 17:03:40 Sure. I will add the comment in a separate CL. I d
24 re.MULTILINE)
25 RESOURCE_EXTRACT_REGEX_PRAGMA_WINDOWS = re.compile(
Raj 2016/05/12 01:40:27 Not tested with Windows yet. Will test asap.
Raj 2016/05/12 01:47:29 I tested in linux for android build, that builds w
26 '^#define (\S*) __pragma\(message\("whitelisted_resource_\d*"\)\) (\d*)$',
rkaplow 2016/05/12 01:52:53 just to verify this isn't a typo - this is lowerca
Raj 2016/05/12 17:03:40 Yes. The pragma format is defined in: https://code
27 re.MULTILINE)
16 28
17 class Error(Exception): 29 class Error(Exception):
18 """Base error class for all exceptions in generated_resources_map.""" 30 """Base error class for all exceptions in generated_resources_map."""
19 31
20 32
21 class HashCollisionError(Error): 33 class HashCollisionError(Error):
22 """Multiple resource names hash to the same value.""" 34 """Multiple resource names hash to the same value."""
23 35
24 36
25 Resource = collections.namedtuple("Resource", ['hash', 'name', 'index']) 37 Resource = collections.namedtuple("Resource", ['hash', 'name', 'index'])
(...skipping 20 matching lines...) Expand all
46 an iterator over all matching (NAME, INDEX) pairs. 58 an iterator over all matching (NAME, INDEX) pairs.
47 59
48 Args: 60 Args:
49 string_to_scan: The input string to scan. 61 string_to_scan: The input string to scan.
50 62
51 Yields: 63 Yields:
52 A tuple of name and index. 64 A tuple of name and index.
53 """ 65 """
54 for match in RESOURCE_EXTRACT_REGEX.finditer(string_to_scan): 66 for match in RESOURCE_EXTRACT_REGEX.finditer(string_to_scan):
55 yield match.group(1, 2) 67 yield match.group(1, 2)
68 for match in RESOURCE_EXTRACT_REGEX_PRAGMA.finditer(string_to_scan):
69 yield match.group(1, 2)
70 for match in RESOURCE_EXTRACT_REGEX_PRAGMA_WINDOWS.finditer(string_to_scan):
71 yield match.group(1, 2)
56 72
57 73
58 def _GetResourceListFromString(resources_content): 74 def _GetResourceListFromString(resources_content):
59 """Produces a list of |Resource| objects from a string. 75 """Produces a list of |Resource| objects from a string.
60 76
61 The input string contains lines of the form "#define NAME INDEX". The returned 77 The input string contains lines of the form "#define NAME INDEX". The returned
62 list is sorted primarily by hash, then name, and then index. 78 list is sorted primarily by hash, then name, and then index.
63 79
64 Args: 80 Args:
65 resources_content: The input string to process, contains lines of the form 81 resources_content: The input string to process, contains lines of the form
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 with open(os.path.join( 304 with open(os.path.join(
289 arguments.output_dir, arguments.source_filename), "w") as generated_file: 305 arguments.output_dir, arguments.source_filename), "w") as generated_file:
290 generated_file.write(source_file_content) 306 generated_file.write(source_file_content)
291 with open(os.path.join( 307 with open(os.path.join(
292 arguments.output_dir, arguments.header_filename), "w") as generated_file: 308 arguments.output_dir, arguments.header_filename), "w") as generated_file:
293 generated_file.write(header_file_content) 309 generated_file.write(header_file_content)
294 310
295 311
296 if __name__ == '__main__': 312 if __name__ == '__main__':
297 sys.exit(main()) 313 sys.exit(main())
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