PageRenderTime 67ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/lahabana/mozilla-central
Python | 77 lines | 62 code | 5 blank | 10 comment | 15 complexity | 25cbe95cbb438d9399071dee50cbe008 MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, LGPL-3.0, AGPL-1.0, LGPL-2.1, BSD-3-Clause, JSON, 0BSD, MIT, MPL-2.0-no-copyleft-exception
  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/.
  5. import sys, os.path, re
  6. commentRE = re.compile(r"\s+#")
  7. conditionsRE = re.compile(r"^(fails|needs-focus|random|skip|asserts|slow|require-or|silentfail|pref|test-pref|ref-pref|fuzzy)")
  8. httpRE = re.compile(r"HTTP\((\.\.(\/\.\.)*)\)")
  9. protocolRE = re.compile(r"^\w+:")
  10. def parseManifest(manifest, dirs):
  11. """Parse the reftest manifest |manifest|, adding all directories containing
  12. tests (and the dirs containing the manifests themselves) to the set |dirs|."""
  13. manifestdir = os.path.dirname(os.path.abspath(manifest))
  14. dirs.add(manifestdir)
  15. f = file(manifest)
  16. urlprefix = ''
  17. for line in f:
  18. if line[0] == '#':
  19. continue # entire line was a comment
  20. m = commentRE.search(line)
  21. if m:
  22. line = line[:m.start()]
  23. line = line.strip()
  24. if not line:
  25. continue
  26. items = line.split()
  27. while conditionsRE.match(items[0]):
  28. del items[0]
  29. if items[0] == "HTTP":
  30. del items[0]
  31. m = httpRE.match(items[0])
  32. if m:
  33. # need to package the dir referenced here
  34. d = os.path.normpath(os.path.join(manifestdir, m.group(1)))
  35. dirs.add(d)
  36. del items[0]
  37. if items[0] == "url-prefix":
  38. urlprefix = items[1]
  39. continue
  40. elif items[0] == "include":
  41. parseManifest(os.path.join(manifestdir, items[1]), dirs)
  42. continue
  43. elif items[0] == "load" or items[0] == "script":
  44. testURLs = [items[1]]
  45. elif items[0] == "==" or items[0] == "!=":
  46. testURLs = items[1:3]
  47. for u in testURLs:
  48. m = protocolRE.match(u)
  49. if m:
  50. # can't very well package about: or data: URIs
  51. continue
  52. d = os.path.dirname(os.path.normpath(os.path.join(manifestdir, urlprefix + u)))
  53. dirs.add(d)
  54. f.close()
  55. def printTestDirs(topsrcdir, topmanifests):
  56. """Parse |topmanifests| and print a list of directories containing the tests
  57. within (and the manifests including those tests), relative to |topsrcdir|."""
  58. topsrcdir = os.path.abspath(topsrcdir)
  59. dirs = set()
  60. for manifest in topmanifests:
  61. parseManifest(manifest, dirs)
  62. for dir in sorted(dirs):
  63. d = dir[len(topsrcdir):].replace('\\','/')
  64. if d[0] == '/':
  65. d = d[1:]
  66. print d
  67. if __name__ == '__main__':
  68. if len(sys.argv) < 3:
  69. print >>sys.stderr, "Usage: %s topsrcdir reftest.list [reftest.list]*" % sys.argv[0]
  70. sys.exit(1)
  71. printTestDirs(sys.argv[1], sys.argv[2:])