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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/tools/reftest/print-manifest-dirs.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,79 @@
     1.4 +#
     1.5 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.8 +
     1.9 +import sys, os.path, re
    1.10 +
    1.11 +commentRE = re.compile(r"\s+#")
    1.12 +conditionsRE = re.compile(r"^(fails|needs-focus|random|skip|asserts|slow|require-or|silentfail|pref|test-pref|ref-pref|fuzzy)")
    1.13 +httpRE = re.compile(r"HTTP\((\.\.(\/\.\.)*)\)")
    1.14 +protocolRE = re.compile(r"^\w+:")
    1.15 +
    1.16 +def parseManifest(manifest, dirs):
    1.17 +  """Parse the reftest manifest |manifest|, adding all directories containing
    1.18 +  tests (and the dirs containing the manifests themselves) to the set |dirs|."""
    1.19 +  manifestdir = os.path.dirname(os.path.abspath(manifest))
    1.20 +  dirs.add(manifestdir)
    1.21 +  f = file(manifest)
    1.22 +  urlprefix = ''
    1.23 +  for line in f:
    1.24 +    if line[0] == '#':
    1.25 +      continue # entire line was a comment
    1.26 +    m = commentRE.search(line)
    1.27 +    if m:
    1.28 +      line = line[:m.start()]
    1.29 +    line = line.strip()
    1.30 +    if not line:
    1.31 +      continue
    1.32 +    items = line.split()
    1.33 +    while conditionsRE.match(items[0]):
    1.34 +      del items[0]
    1.35 +    if items[0] == "HTTP":
    1.36 +      del items[0]
    1.37 +    m = httpRE.match(items[0])
    1.38 +    if m:
    1.39 +      # need to package the dir referenced here
    1.40 +      d = os.path.normpath(os.path.join(manifestdir, m.group(1)))
    1.41 +      dirs.add(d)
    1.42 +      del items[0]
    1.43 +
    1.44 +    if items[0] == "url-prefix":
    1.45 +      urlprefix = items[1]
    1.46 +      continue
    1.47 +    elif items[0] == "default-preferences":
    1.48 +      continue
    1.49 +    elif items[0] == "include":
    1.50 +      parseManifest(os.path.join(manifestdir, items[1]), dirs)
    1.51 +      continue
    1.52 +    elif items[0] == "load" or items[0] == "script":
    1.53 +      testURLs = [items[1]]
    1.54 +    elif items[0] == "==" or items[0] == "!=":
    1.55 +      testURLs = items[1:3]
    1.56 +    for u in testURLs:
    1.57 +      m = protocolRE.match(u)
    1.58 +      if m:
    1.59 +        # can't very well package about: or data: URIs
    1.60 +        continue
    1.61 +      d = os.path.dirname(os.path.normpath(os.path.join(manifestdir, urlprefix + u)))
    1.62 +      dirs.add(d)
    1.63 +  f.close()
    1.64 +
    1.65 +def printTestDirs(topsrcdir, topmanifests):
    1.66 +  """Parse |topmanifests| and print a list of directories containing the tests
    1.67 +  within (and the manifests including those tests), relative to |topsrcdir|."""
    1.68 +  topsrcdir = os.path.abspath(topsrcdir)
    1.69 +  dirs = set()
    1.70 +  for manifest in topmanifests:
    1.71 +    parseManifest(manifest, dirs)
    1.72 +  for dir in sorted(dirs):
    1.73 +    d = dir[len(topsrcdir):].replace('\\','/')
    1.74 +    if d[0] == '/':
    1.75 +      d = d[1:]
    1.76 +    print d
    1.77 +
    1.78 +if __name__ == '__main__':
    1.79 +  if len(sys.argv) < 3:
    1.80 +    print >>sys.stderr, "Usage: %s topsrcdir reftest.list [reftest.list]*" % sys.argv[0]
    1.81 +    sys.exit(1)
    1.82 +  printTestDirs(sys.argv[1], sys.argv[2:])

mercurial