michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: import sys, os.path, re michael@0: michael@0: commentRE = re.compile(r"\s+#") michael@0: conditionsRE = re.compile(r"^(fails|needs-focus|random|skip|asserts|slow|require-or|silentfail|pref|test-pref|ref-pref|fuzzy)") michael@0: httpRE = re.compile(r"HTTP\((\.\.(\/\.\.)*)\)") michael@0: protocolRE = re.compile(r"^\w+:") michael@0: michael@0: def parseManifest(manifest, dirs): michael@0: """Parse the reftest manifest |manifest|, adding all directories containing michael@0: tests (and the dirs containing the manifests themselves) to the set |dirs|.""" michael@0: manifestdir = os.path.dirname(os.path.abspath(manifest)) michael@0: dirs.add(manifestdir) michael@0: f = file(manifest) michael@0: urlprefix = '' michael@0: for line in f: michael@0: if line[0] == '#': michael@0: continue # entire line was a comment michael@0: m = commentRE.search(line) michael@0: if m: michael@0: line = line[:m.start()] michael@0: line = line.strip() michael@0: if not line: michael@0: continue michael@0: items = line.split() michael@0: while conditionsRE.match(items[0]): michael@0: del items[0] michael@0: if items[0] == "HTTP": michael@0: del items[0] michael@0: m = httpRE.match(items[0]) michael@0: if m: michael@0: # need to package the dir referenced here michael@0: d = os.path.normpath(os.path.join(manifestdir, m.group(1))) michael@0: dirs.add(d) michael@0: del items[0] michael@0: michael@0: if items[0] == "url-prefix": michael@0: urlprefix = items[1] michael@0: continue michael@0: elif items[0] == "default-preferences": michael@0: continue michael@0: elif items[0] == "include": michael@0: parseManifest(os.path.join(manifestdir, items[1]), dirs) michael@0: continue michael@0: elif items[0] == "load" or items[0] == "script": michael@0: testURLs = [items[1]] michael@0: elif items[0] == "==" or items[0] == "!=": michael@0: testURLs = items[1:3] michael@0: for u in testURLs: michael@0: m = protocolRE.match(u) michael@0: if m: michael@0: # can't very well package about: or data: URIs michael@0: continue michael@0: d = os.path.dirname(os.path.normpath(os.path.join(manifestdir, urlprefix + u))) michael@0: dirs.add(d) michael@0: f.close() michael@0: michael@0: def printTestDirs(topsrcdir, topmanifests): michael@0: """Parse |topmanifests| and print a list of directories containing the tests michael@0: within (and the manifests including those tests), relative to |topsrcdir|.""" michael@0: topsrcdir = os.path.abspath(topsrcdir) michael@0: dirs = set() michael@0: for manifest in topmanifests: michael@0: parseManifest(manifest, dirs) michael@0: for dir in sorted(dirs): michael@0: d = dir[len(topsrcdir):].replace('\\','/') michael@0: if d[0] == '/': michael@0: d = d[1:] michael@0: print d michael@0: michael@0: if __name__ == '__main__': michael@0: if len(sys.argv) < 3: michael@0: print >>sys.stderr, "Usage: %s topsrcdir reftest.list [reftest.list]*" % sys.argv[0] michael@0: sys.exit(1) michael@0: printTestDirs(sys.argv[1], sys.argv[2:])