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

Side by Side Diff: native_client_sdk/src/tools/fix_deps.py

Issue 720233003: [NaCl SDK] Convert python scripts from optparse to argparse. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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 | « native_client_sdk/src/tools/decode_dump.py ('k') | native_client_sdk/src/tools/fix_manifest.py » ('j') | 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/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 """Fixup GCC-generated dependency files. 6 """Fixup GCC-generated dependency files.
7 7
8 Modify GCC generated dependency files so they are more suitable for including 8 Modify GCC generated dependency files so they are more suitable for including
9 in a GNU Makefile. Without the fixups, deleting or renaming headers can cause 9 in a GNU Makefile. Without the fixups, deleting or renaming headers can cause
10 the build to be broken. 10 the build to be broken.
11 11
12 See http://mad-scientist.net/make/autodep.html for more details of the problem. 12 See http://mad-scientist.net/make/autodep.html for more details of the problem.
13 """ 13 """
14 14
15 import argparse
15 import os 16 import os
16 import optparse
17 import sys 17 import sys
18 18
19 TAG_LINE = '# Updated by fix_deps.py\n' 19 TAG_LINE = '# Updated by fix_deps.py\n'
20 20
21 21
22 class Error(Exception): 22 class Error(Exception):
23 pass 23 pass
24 24
25 25
26 def ParseLine(line, new_target): 26 def ParseLine(line, new_target):
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 # For every depenency found output a dummy target with no rules 75 # For every depenency found output a dummy target with no rules
76 for dep in deps: 76 for dep in deps:
77 outlines.append('%s:\n' % dep) 77 outlines.append('%s:\n' % dep)
78 78
79 with open(output_filename, 'w') as outfile: 79 with open(output_filename, 'w') as outfile:
80 for line in outlines: 80 for line in outlines:
81 outfile.write(line) 81 outfile.write(line)
82 82
83 83
84 def main(argv): 84 def main(argv):
85 usage = "usage: %prog [options] <dep_file>" 85 parser = argparse.ArgumentParser(description=__doc__)
86 parser = optparse.OptionParser(usage=usage, description=__doc__) 86 parser.add_argument('-o', '--output', help='Output filename (defaults to '
87 parser.add_option('-o', '--output', help='Output filename (defaults to '
88 'input name with .deps extension') 87 'input name with .deps extension')
89 parser.add_option('-c', '--clean', action='store_true', 88 parser.add_argument('-c', '--clean', action='store_true',
90 help='Remove input file after writing output') 89 help='Remove input file after writing output')
91 options, args = parser.parse_args(argv) 90 parser.add_argument('dep_file')
92 if not args: 91 options = parser.parse_args(argv)
93 raise parser.error('No input file specified')
94 if len(args) > 1:
95 raise parser.error('Only one argument supported')
96 input_filename = args[0]
97 output_filename = options.output 92 output_filename = options.output
98 if not output_filename: 93 if not output_filename:
99 output_filename = os.path.splitext(input_filename)[0] + '.deps' 94 output_filename = os.path.splitext(options.dep_file)[0] + '.deps'
100 FixupDepFile(input_filename, output_filename) 95 FixupDepFile(options.dep_file, output_filename)
101 if options.clean and input_filename != output_filename: 96 if options.clean and options.dep_file != output_filename:
102 os.remove(input_filename) 97 os.remove(options.dep_file)
98
103 return 0 99 return 0
104 100
105 101
106 if __name__ == '__main__': 102 if __name__ == '__main__':
107 try: 103 try:
108 sys.exit(main(sys.argv[1:])) 104 sys.exit(main(sys.argv[1:]))
109 except Error as e: 105 except Error as e:
110 sys.stderr.write('%s: %s\n' % (os.path.basename(__file__), e)) 106 sys.stderr.write('%s: %s\n' % (os.path.basename(__file__), e))
111 sys.exit(1) 107 sys.exit(1)
OLDNEW
« no previous file with comments | « native_client_sdk/src/tools/decode_dump.py ('k') | native_client_sdk/src/tools/fix_manifest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698