PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/bgirard/mozilla-central
Python | 110 lines | 62 code | 5 blank | 43 comment | 15 complexity | 7c59b6198afacd78d17c1fd20ea18c1a MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause, GPL-2.0, Apache-2.0, MIT, JSON, 0BSD, BSD-2-Clause, LGPL-3.0, AGPL-1.0
  1. #
  2. # ***** BEGIN LICENSE BLOCK *****
  3. # Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. #
  5. # The contents of this file are subject to the Mozilla Public License Version
  6. # 1.1 (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. # http://www.mozilla.org/MPL/
  9. #
  10. # Software distributed under the License is distributed on an "AS IS" basis,
  11. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. # for the specific language governing rights and limitations under the
  13. # License.
  14. #
  15. # The Original Code is mozilla.org code.
  16. #
  17. # The Initial Developer of the Original Code is
  18. # Mozilla Foundation.
  19. # Portions created by the Initial Developer are Copyright (C) 2009
  20. # the Initial Developer. All Rights Reserved.
  21. #
  22. # Contributor(s):
  23. # Ted Mielczarek <ted.mielczarek@gmail.com>
  24. #
  25. # Alternatively, the contents of this file may be used under the terms of
  26. # either the GNU General Public License Version 2 or later (the "GPL"), or
  27. # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28. # in which case the provisions of the GPL or the LGPL are applicable instead
  29. # of those above. If you wish to allow use of your version of this file only
  30. # under the terms of either the GPL or the LGPL, and not to allow others to
  31. # use your version of this file under the terms of the MPL, indicate your
  32. # decision by deleting the provisions above and replace them with the notice
  33. # and other provisions required by the GPL or the LGPL. If you do not delete
  34. # the provisions above, a recipient may use your version of this file under
  35. # the terms of any one of the MPL, the GPL or the LGPL.
  36. #
  37. # ***** END LICENSE BLOCK *****
  38. import sys, os.path, re
  39. commentRE = re.compile(r"\s+#")
  40. conditionsRE = re.compile(r"^(fails|needs-focus|random|skip|asserts|slow|require-or|silentfail|pref|test-pref|ref-pref|fuzzy)")
  41. httpRE = re.compile(r"HTTP\((\.\.(\/\.\.)*)\)")
  42. protocolRE = re.compile(r"^\w+:")
  43. def parseManifest(manifest, dirs):
  44. """Parse the reftest manifest |manifest|, adding all directories containing
  45. tests (and the dirs containing the manifests themselves) to the set |dirs|."""
  46. manifestdir = os.path.dirname(os.path.abspath(manifest))
  47. dirs.add(manifestdir)
  48. f = file(manifest)
  49. urlprefix = ''
  50. for line in f:
  51. if line[0] == '#':
  52. continue # entire line was a comment
  53. m = commentRE.search(line)
  54. if m:
  55. line = line[:m.start()]
  56. line = line.strip()
  57. if not line:
  58. continue
  59. items = line.split()
  60. while conditionsRE.match(items[0]):
  61. del items[0]
  62. if items[0] == "HTTP":
  63. del items[0]
  64. m = httpRE.match(items[0])
  65. if m:
  66. # need to package the dir referenced here
  67. d = os.path.normpath(os.path.join(manifestdir, m.group(1)))
  68. dirs.add(d)
  69. del items[0]
  70. if items[0] == "url-prefix":
  71. urlprefix = items[1]
  72. continue
  73. elif items[0] == "include":
  74. parseManifest(os.path.join(manifestdir, items[1]), dirs)
  75. continue
  76. elif items[0] == "load" or items[0] == "script":
  77. testURLs = [items[1]]
  78. elif items[0] == "==" or items[0] == "!=":
  79. testURLs = items[1:3]
  80. for u in testURLs:
  81. m = protocolRE.match(u)
  82. if m:
  83. # can't very well package about: or data: URIs
  84. continue
  85. d = os.path.dirname(os.path.normpath(os.path.join(manifestdir, urlprefix + u)))
  86. dirs.add(d)
  87. f.close()
  88. def printTestDirs(topsrcdir, topmanifests):
  89. """Parse |topmanifests| and print a list of directories containing the tests
  90. within (and the manifests including those tests), relative to |topsrcdir|."""
  91. topsrcdir = os.path.abspath(topsrcdir)
  92. dirs = set()
  93. for manifest in topmanifests:
  94. parseManifest(manifest, dirs)
  95. for dir in sorted(dirs):
  96. d = dir[len(topsrcdir):].replace('\\','/')
  97. if d[0] == '/':
  98. d = d[1:]
  99. print d
  100. if __name__ == '__main__':
  101. if len(sys.argv) < 3:
  102. print >>sys.stderr, "Usage: %s topsrcdir reftest.list [reftest.list]*" % sys.argv[0]
  103. sys.exit(1)
  104. printTestDirs(sys.argv[1], sys.argv[2:])