Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
1 #
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 import sys, os.path, re
8 commentRE = re.compile(r"\s+#")
9 conditionsRE = re.compile(r"^(fails|needs-focus|random|skip|asserts|slow|require-or|silentfail|pref|test-pref|ref-pref|fuzzy)")
10 httpRE = re.compile(r"HTTP\((\.\.(\/\.\.)*)\)")
11 protocolRE = re.compile(r"^\w+:")
13 def parseManifest(manifest, dirs):
14 """Parse the reftest manifest |manifest|, adding all directories containing
15 tests (and the dirs containing the manifests themselves) to the set |dirs|."""
16 manifestdir = os.path.dirname(os.path.abspath(manifest))
17 dirs.add(manifestdir)
18 f = file(manifest)
19 urlprefix = ''
20 for line in f:
21 if line[0] == '#':
22 continue # entire line was a comment
23 m = commentRE.search(line)
24 if m:
25 line = line[:m.start()]
26 line = line.strip()
27 if not line:
28 continue
29 items = line.split()
30 while conditionsRE.match(items[0]):
31 del items[0]
32 if items[0] == "HTTP":
33 del items[0]
34 m = httpRE.match(items[0])
35 if m:
36 # need to package the dir referenced here
37 d = os.path.normpath(os.path.join(manifestdir, m.group(1)))
38 dirs.add(d)
39 del items[0]
41 if items[0] == "url-prefix":
42 urlprefix = items[1]
43 continue
44 elif items[0] == "default-preferences":
45 continue
46 elif items[0] == "include":
47 parseManifest(os.path.join(manifestdir, items[1]), dirs)
48 continue
49 elif items[0] == "load" or items[0] == "script":
50 testURLs = [items[1]]
51 elif items[0] == "==" or items[0] == "!=":
52 testURLs = items[1:3]
53 for u in testURLs:
54 m = protocolRE.match(u)
55 if m:
56 # can't very well package about: or data: URIs
57 continue
58 d = os.path.dirname(os.path.normpath(os.path.join(manifestdir, urlprefix + u)))
59 dirs.add(d)
60 f.close()
62 def printTestDirs(topsrcdir, topmanifests):
63 """Parse |topmanifests| and print a list of directories containing the tests
64 within (and the manifests including those tests), relative to |topsrcdir|."""
65 topsrcdir = os.path.abspath(topsrcdir)
66 dirs = set()
67 for manifest in topmanifests:
68 parseManifest(manifest, dirs)
69 for dir in sorted(dirs):
70 d = dir[len(topsrcdir):].replace('\\','/')
71 if d[0] == '/':
72 d = d[1:]
73 print d
75 if __name__ == '__main__':
76 if len(sys.argv) < 3:
77 print >>sys.stderr, "Usage: %s topsrcdir reftest.list [reftest.list]*" % sys.argv[0]
78 sys.exit(1)
79 printTestDirs(sys.argv[1], sys.argv[2:])