File: mkssldef.py

package info (click to toggle)
nodejs 4.8.2~dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 62,476 kB
  • ctags: 111,183
  • sloc: cpp: 661,544; ansic: 31,406; python: 23,073; makefile: 1,418; sh: 1,384; perl: 255; lisp: 222; ruby: 76; xml: 50
file content (44 lines) | stat: -rwxr-xr-x 1,420 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python

from __future__ import print_function
import re
import sys

categories = []
defines = []
excludes = []

if __name__ == '__main__':
  out = sys.stdout
  filenames = sys.argv[1:]

  while filenames and filenames[0].startswith('-'):
    option = filenames.pop(0)
    if option == '-o': out = open(filenames.pop(0), 'w')
    elif option.startswith('-C'): categories += option[2:].split(',')
    elif option.startswith('-D'): defines += option[2:].split(',')
    elif option.startswith('-X'): excludes += option[2:].split(',')

  excludes = map(re.compile, excludes)
  exported = []

  for filename in filenames:
    for line in open(filename).readlines():
      name, _, meta, _ = re.split('\s+', line)
      if any(map(lambda p: p.match(name), excludes)): continue
      meta = meta.split(':')
      assert meta[0] in ('EXIST', 'NOEXIST')
      assert meta[2] in ('FUNCTION', 'VARIABLE')
      if meta[0] != 'EXIST': continue
      if meta[2] != 'FUNCTION': continue
      def satisfy(expr, rules):
        def test(expr):
          if expr.startswith('!'): return not expr[1:] in rules
          return expr == '' or expr in rules
        return all(map(test, expr.split(',')))
      if not satisfy(meta[1], defines): continue
      if not satisfy(meta[3], categories): continue
      exported.append(name)

  print('EXPORTS', file=out)
  for name in sorted(exported): print('    ', name, file=out)