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