ยปCore Development>Code coverage>Tools/freeze/checkextensions.py

Python code coverage for Tools/freeze/checkextensions.py

#countcontent
1n/a# Check for a module in a set of extension directories.
2n/a# An extension directory should contain a Setup file
3n/a# and one or more .o files or a lib.a file.
4n/a
5n/aimport os
6n/aimport parsesetup
7n/a
8n/adef checkextensions(unknown, extensions):
9n/a files = []
10n/a modules = []
11n/a edict = {}
12n/a for e in extensions:
13n/a setup = os.path.join(e, 'Setup')
14n/a liba = os.path.join(e, 'lib.a')
15n/a if not os.path.isfile(liba):
16n/a liba = None
17n/a edict[e] = parsesetup.getsetupinfo(setup), liba
18n/a for mod in unknown:
19n/a for e in extensions:
20n/a (mods, vars), liba = edict[e]
21n/a if mod not in mods:
22n/a continue
23n/a modules.append(mod)
24n/a if liba:
25n/a # If we find a lib.a, use it, ignore the
26n/a # .o files, and use *all* libraries for
27n/a # *all* modules in the Setup file
28n/a if liba in files:
29n/a break
30n/a files.append(liba)
31n/a for m in list(mods.keys()):
32n/a files = files + select(e, mods, vars,
33n/a m, 1)
34n/a break
35n/a files = files + select(e, mods, vars, mod, 0)
36n/a break
37n/a return files, modules
38n/a
39n/adef select(e, mods, vars, mod, skipofiles):
40n/a files = []
41n/a for w in mods[mod]:
42n/a w = treatword(w)
43n/a if not w:
44n/a continue
45n/a w = expandvars(w, vars)
46n/a for w in w.split():
47n/a if skipofiles and w[-2:] == '.o':
48n/a continue
49n/a # Assume $var expands to absolute pathname
50n/a if w[0] not in ('-', '$') and w[-2:] in ('.o', '.a'):
51n/a w = os.path.join(e, w)
52n/a if w[:2] in ('-L', '-R') and w[2:3] != '$':
53n/a w = w[:2] + os.path.join(e, w[2:])
54n/a files.append(w)
55n/a return files
56n/a
57n/acc_flags = ['-I', '-D', '-U']
58n/acc_exts = ['.c', '.C', '.cc', '.c++']
59n/a
60n/adef treatword(w):
61n/a if w[:2] in cc_flags:
62n/a return None
63n/a if w[:1] == '-':
64n/a return w # Assume loader flag
65n/a head, tail = os.path.split(w)
66n/a base, ext = os.path.splitext(tail)
67n/a if ext in cc_exts:
68n/a tail = base + '.o'
69n/a w = os.path.join(head, tail)
70n/a return w
71n/a
72n/adef expandvars(str, vars):
73n/a i = 0
74n/a while i < len(str):
75n/a i = k = str.find('$', i)
76n/a if i < 0:
77n/a break
78n/a i = i+1
79n/a var = str[i:i+1]
80n/a i = i+1
81n/a if var == '(':
82n/a j = str.find(')', i)
83n/a if j < 0:
84n/a break
85n/a var = str[i:j]
86n/a i = j+1
87n/a if var in vars:
88n/a str = str[:k] + vars[var] + str[i:]
89n/a i = k
90n/a return str