summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/manifestupdate.py
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /testing/web-platform/manifestupdate.py
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/web-platform/manifestupdate.py')
-rw-r--r--testing/web-platform/manifestupdate.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/testing/web-platform/manifestupdate.py b/testing/web-platform/manifestupdate.py
new file mode 100644
index 000000000..7b15a55eb
--- /dev/null
+++ b/testing/web-platform/manifestupdate.py
@@ -0,0 +1,89 @@
+import argparse
+import imp
+import os
+import sys
+
+from mozlog.structured import commandline
+from wptrunner.wptcommandline import get_test_paths, set_from_config
+from wptrunner.testloader import ManifestLoader
+
+def create_parser():
+ p = argparse.ArgumentParser()
+ p.add_argument("--check-clean", action="store_true",
+ help="Check that updating the manifest doesn't lead to any changes")
+ commandline.add_logging_group(p)
+
+ return p
+
+
+def update(logger, wpt_dir, check_clean=True):
+ localpaths = imp.load_source("localpaths",
+ os.path.join(wpt_dir, "tests", "tools", "localpaths.py"))
+ kwargs = {"config": os.path.join(wpt_dir, "wptrunner.ini"),
+ "tests_root": None,
+ "metadata_root": None}
+
+ set_from_config(kwargs)
+ config = kwargs["config"]
+ test_paths = get_test_paths(config)
+
+ if check_clean:
+ old_manifests = {}
+ for data in test_paths.itervalues():
+ path = os.path.join(data["metadata_path"], "MANIFEST.json")
+ with open(path) as f:
+ old_manifests[path] = f.readlines()
+
+ try:
+ ManifestLoader(test_paths, force_manifest_update=True).load()
+
+ rv = 0
+
+ if check_clean:
+ clean = diff_manifests(logger, old_manifests)
+ if not clean:
+ rv = 1
+ finally:
+ if check_clean:
+ for path, data in old_manifests.iteritems():
+ logger.info("Restoring manifest %s" % path)
+ with open(path, "w") as f:
+ f.writelines(data)
+
+ return rv
+
+def diff_manifests(logger, old_manifests):
+ logger.info("Diffing old and new manifests")
+ import difflib
+
+ clean = True
+ for path, old in old_manifests.iteritems():
+ with open(path) as f:
+ new = f.readlines()
+
+ if old != new:
+ clean = False
+ sm = difflib.SequenceMatcher(a=old, b=new)
+ for group in sm.get_grouped_opcodes():
+ logged = False
+ message = []
+ for op, old_0, old_1, new_0, new_1 in group:
+ if op != "equal" and not logged:
+ logged = True
+ logger.lint_error(path=path,
+ message="Manifest changed",
+ lineno=(old_0 + 1),
+ source="\n".join(old[old_0:old_1]),
+ linter="wpt-manifest")
+ if op == "equal":
+ message.extend(' ' + line for line in old[old_0:old_1])
+ if op in ('replace', 'delete'):
+ message.extend('-' + line for line in old[old_0:old_1])
+ if op in ('replace', 'insert'):
+ message.extend('+' + line for line in new[new_0:new_1])
+ logger.info("".join(message))
+ if clean:
+ logger.info("No differences found")
+
+ return clean
+