OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 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 optparse | 6 import argparse |
7 import os | 7 import os |
8 import re | 8 import re |
9 import sys | 9 import sys |
10 | 10 |
11 import build_version | 11 import build_version |
12 from build_paths import SDK_SRC_DIR, SCRIPT_DIR, OUT_DIR | 12 from build_paths import SDK_SRC_DIR, SCRIPT_DIR, OUT_DIR |
13 | 13 |
14 # Add SDK make tools scripts to the python path. | 14 # Add SDK make tools scripts to the python path. |
15 sys.path.append(os.path.join(SDK_SRC_DIR, 'tools')) | 15 sys.path.append(os.path.join(SDK_SRC_DIR, 'tools')) |
16 | 16 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 line2 = SplitPattern(line2)[0].lower() | 175 line2 = SplitPattern(line2)[0].lower() |
176 return cmp(line1, line2) | 176 return cmp(line1, line2) |
177 | 177 |
178 lines.sort(compare) | 178 lines.sort(compare) |
179 with open(rule_path, 'w') as output: | 179 with open(rule_path, 'w') as output: |
180 for line in lines: | 180 for line in lines: |
181 output.write(line) | 181 output.write(line) |
182 | 182 |
183 | 183 |
184 def main(args): | 184 def main(args): |
185 parser = optparse.OptionParser(usage='%prog <rule file> <directory>') | 185 parser = argparse.ArgumentParser(description=__doc__) |
186 parser.add_option('-p', '--platform', | 186 parser.add_argument('-p', '--platform', |
187 help='Test with this platform, instead of the system\'s platform') | 187 help='Test with this platform, instead of the system\'s platform') |
188 parser.add_option('-s', '--sort', action='store_true', | 188 parser.add_argument('-s', '--sort', action='store_true', |
189 help='Sort the file list in place, rather than verifying the contents.') | 189 help='Sort the file list in place, rather than verifying the contents.') |
190 options, args = parser.parse_args(args) | 190 parser.add_argument('rule_file', nargs='?', |
191 | 191 default=os.path.join(SCRIPT_DIR, 'sdk_files.list')) |
192 if not args: | 192 parser.add_argument('directory_path', nargs='?') |
193 args = [os.path.join(SCRIPT_DIR, 'sdk_files.list')] | 193 options = parser.parse_args(args) |
194 | 194 |
195 if options.sort: | 195 if options.sort: |
196 if not args: | 196 SortFile(options.rule_file) |
197 parser.error('Expected rule file.') | |
198 SortFile(args[0]) | |
199 return 0 | 197 return 0 |
200 | 198 |
201 if len(args) < 2: | 199 if not options.directory_path: |
202 version = build_version.ChromeMajorVersion() | 200 version = build_version.ChromeMajorVersion() |
203 args.append(os.path.join(OUT_DIR, 'pepper_%s' % version)) | 201 options.directory_path = os.path.join(OUT_DIR, 'pepper_%s' % version) |
204 | 202 |
205 rule_path, directory_path = args | |
206 if options.platform: | 203 if options.platform: |
207 if options.platform not in VALID_PLATFORMS: | 204 if options.platform not in VALID_PLATFORMS: |
208 parser.error('Unknown platform: %s' % options.platform) | 205 parser.error('Unknown platform: %s' % options.platform) |
209 platform = options.platform | 206 platform = options.platform |
210 else: | 207 else: |
211 platform = getos.GetPlatform() | 208 platform = getos.GetPlatform() |
212 | 209 |
213 try: | 210 try: |
214 return Verify(rule_path, directory_path, platform) | 211 return Verify(options.rule_file, options.directory_path, platform) |
215 except ParseException, e: | 212 except ParseException, e: |
216 print >> sys.stderr, 'Error parsing rules:\n', e | 213 sys.stderr.write('Error parsing rules:\n%s' % e) |
binji
2014/11/13 23:57:02
additional \n after %s
Sam Clegg
2014/11/30 17:55:11
Done.
| |
217 return 1 | 214 return 1 |
218 except VerifyException, e: | 215 except VerifyException, e: |
219 print >> sys.stderr, 'Error verifying file list:\n', e | 216 sys.stderr.write('Error verifying file list:\n%s' % e) |
220 return 1 | 217 return 1 |
221 return 0 | 218 return 0 |
222 | 219 |
223 | 220 |
224 if __name__ == '__main__': | 221 if __name__ == '__main__': |
225 sys.exit(main(sys.argv[1:])) | 222 sys.exit(main(sys.argv[1:])) |
OLD | NEW |