OLD | NEW |
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 """Verifies that GRD resource files define all the strings used by a given | 6 """Verifies that GRD resource files define all the strings used by a given |
7 set of source files. For file formats where it is not possible to infer which | 7 set of source files. For file formats where it is not possible to infer which |
8 strings represent message identifiers, localized strings should be explicitly | 8 strings represent message identifiers, localized strings should be explicitly |
9 annotated with the string "i18n-content", for example: | 9 annotated with the string "i18n-content", for example: |
10 | 10 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 return result | 121 return result |
122 | 122 |
123 | 123 |
124 def main(): | 124 def main(): |
125 parser = optparse.OptionParser( | 125 parser = optparse.OptionParser( |
126 usage='Usage: %prog [options...] [source_file...]') | 126 usage='Usage: %prog [options...] [source_file...]') |
127 parser.add_option('-t', '--touch', dest='touch', | 127 parser.add_option('-t', '--touch', dest='touch', |
128 help='File to touch when finished.') | 128 help='File to touch when finished.') |
129 parser.add_option('-r', '--grd', dest='grd', action='append', | 129 parser.add_option('-r', '--grd', dest='grd', action='append', |
130 help='grd file') | 130 help='grd file') |
| 131 parser.add_option('--strict', dest='strict', action='store_true', |
| 132 help='Use strict verification checks.') |
131 | 133 |
132 options, args = parser.parse_args() | 134 options, args = parser.parse_args() |
133 if not options.touch: | 135 if not options.touch: |
134 print '-t is not specified.' | 136 print '-t is not specified.' |
135 return 1 | 137 return 1 |
136 if len(options.grd) == 0 or len(args) == 0: | 138 if len(options.grd) == 0 or len(args) == 0: |
137 print 'At least one GRD file needs to be specified.' | 139 print 'At least one GRD file needs to be specified.' |
138 return 1 | 140 return 1 |
139 | 141 |
140 all_resources = [] | 142 all_resources = [] |
141 non_android_resources = [] | 143 non_android_resources = [] |
142 for f in options.grd: | 144 for f in options.grd: |
143 android_tags, other_tags = LoadTagsFromGrd(f) | 145 android_tags, other_tags = LoadTagsFromGrd(f) |
144 all_resources.extend(android_tags + other_tags) | 146 all_resources.extend(android_tags + other_tags) |
145 non_android_resources.extend(other_tags) | 147 non_android_resources.extend(other_tags) |
146 | 148 |
147 used_tags = set([]) | 149 used_tags = set([]) |
148 exit_code = 0 | 150 exit_code = 0 |
149 for f in args: | 151 for f in args: |
150 if not VerifyFile(f, all_resources, used_tags): | 152 if not VerifyFile(f, all_resources, used_tags): |
151 exit_code = 1 | 153 exit_code = 1 |
152 | 154 |
153 # Determining if a resource is being used in the Android app is tricky | 155 if options.strict: |
154 # because it requires annotating and parsing Android XML layout files. | 156 warnings = False |
155 # For now, exclude Android strings from this check. | 157 # Determining if a resource is being used in the Android app is tricky |
156 warnings = False | 158 # because it requires annotating and parsing Android XML layout files. |
157 for tag in non_android_resources: | 159 # For now, exclude Android strings from this check. |
158 if tag not in used_tags: | 160 for tag in non_android_resources: |
159 print ('%s/%s:0: warning: %s is defined but not used') % \ | 161 if tag not in used_tags: |
160 (os.getcwd(), sys.argv[2], tag) | 162 print ('%s/%s:0: warning: %s is defined but not used') % \ |
161 warnings = True | 163 (os.getcwd(), sys.argv[2], tag) |
162 if warnings: | 164 warnings = True |
163 print WARNING_MESSAGE | 165 if warnings: |
| 166 print WARNING_MESSAGE |
164 | 167 |
165 if exit_code == 0: | 168 if exit_code == 0: |
166 f = open(options.touch, 'a') | 169 f = open(options.touch, 'a') |
167 f.close() | 170 f.close() |
168 os.utime(options.touch, None) | 171 os.utime(options.touch, None) |
169 | 172 |
170 return exit_code | 173 return exit_code |
171 | 174 |
172 | 175 |
173 if __name__ == '__main__': | 176 if __name__ == '__main__': |
174 sys.exit(main()) | 177 sys.exit(main()) |
OLD | NEW |