mdep-idea-1.diff

Lakie, 2011-03-21 16:04

Download (1.69 KB)

View differences:

scripts/mdep.py Sat Mar 19 16:43:30 2011 +0000
4 4
include_pat = re.compile(r'#include\s*"([^"]*)"')
5 5
pcx_pat = re.compile(r'\s(\S+\.[pP][cCnN][xXgG])\s')
6 6

  
7
def scan_file(fname):
7
def scan_file(include_dirs, fname):
8 8
    """
9 9
    Scan a file for other files it needs.
10 10

  
11
    @param include_dirs: Directories to try.
12
    @type  include_dirs: C{list} of C{str}
13

  
11 14
    @param fname: Name of the file to scan.
12 15
    @type  fname: C{str}
13 16

  
14 17
    @return: Included source files, included graphics files.
15 18
    @rtype:  C{set} of C{str}, C{set} of C{str}
16 19
    """
20
    fold = os.path.dirname(fname)
17 21
    fp = open(fname, 'r')
18 22
    line = fp.read()
19 23
    fp.close()
......
24 28
    while s < len(data):
25 29
        m = include_pat.search(data, s)
26 30
        if m:
27
            includes.add(m.group(1))
31
            iname = m.group(1)
32
            found = False
33
            for base in include_dirs:
34
               if iname.startswith(base):
35
                   found = True
36
                   break;
37
            if not found:
38
                iname = os.path.normpath(os.path.join(fold, iname))
39
            includes.add(iname)
28 40
            s = m.end()
29 41
        else:
30 42
            break
......
118 130
    # Collect files.
119 131
    while notdone:
120 132
        fname = notdone.pop()
121
        includes, graphics = scan_file(fname)
133
        includes, graphics = scan_file(opt_dict['include_dirs'], fname)
122 134
        good_inc, bad_inc = check_existence(opt_dict['include_dirs'], includes)
123 135
        good_gfx, bad_gfx = check_existence(opt_dict['include_dirs'], graphics)
124 136
        dependencies[fname] = good_inc.union(bad_inc) \