annotate python/make-targets.py @ 462:48deb57f52d1

python/setup_repo.py
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 10 Aug 2013 18:20:53 -0700
parents 71345f4de3ce
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
343
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/python
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 list the targets for a makefile
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 """
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 import argparse
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 import subprocess
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 import sys
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 call = subprocess.check_output
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 def main(args=sys.argv[1:]):
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 ignore = ['%', '.', '(', '/']
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 parser = argparse.ArgumentParser()
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 parser.add_argument("-a", "--all", action="store_true",
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 help="show all matches")
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 parser.add_argument("--origin", action="store_true",
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 help="show original line")
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22 args = parser.parse_args(args)
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24 if args.all:
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25 ignore = []
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27 line_dict = {}
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
28 names = []
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
29 output = call(["make", "-pn"]).strip()
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
30 for index, line in enumerate(output.splitlines()):
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
31 _orig = line
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
32 line = line.strip()
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
33 if not line:
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
34 continue
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
35 if line.startswith('#'):
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
36 continue
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
37 if ':' not in line:
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
38 continue
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
39 name, rhs = line.split(':', 1)
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
40 if rhs and rhs[0] == '=':
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
41 continue
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
42 name = name.strip()
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
43 if '=' in name or not name:
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
44 continue
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
45
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
46 # ignore thingies
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
47 if name.startswith(tuple(ignore)):
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
48 continue
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
49
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
50 names.append(name)
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
51 line_dict.setdefault(name, (index, _orig))
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
52
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
53 names = list(set(names))
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
54 names.sort()
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
55 if args.origin:
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
56 for name in names:
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
57 index, line = line_dict[name]
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
58 print '%s: `%s`:%d' % (name, line, index+1)
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
59 return
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
60 print '\n'.join(names)
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
61
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
62 if __name__ == '__main__':
71345f4de3ce programs to list make targets
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
63 main()