layout/tools/reftest/print-manifest-dirs.py

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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

mercurial