Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Unified Diff: tools/presubmit.py

Issue 1477403002: [test+presubmit] Remove duplicate test status file entries (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: remove global variable hack Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/presubmit.py
diff --git a/tools/presubmit.py b/tools/presubmit.py
index 0e86063d6de89f2ef8911c4b721ca36d62c54c0b..3f0fa2b913917dcba3e1f4d60eebcffef3a48e7e 100755
--- a/tools/presubmit.py
+++ b/tools/presubmit.py
@@ -35,6 +35,7 @@ except ImportError, e:
md5er = md5.new
+import json
import optparse
import os
from os.path import abspath, join, dirname, basename, exists
@@ -407,7 +408,51 @@ def CheckExternalReferenceRegistration(workspace):
[sys.executable, join(workspace, "tools", "external-reference-check.py")])
return code == 0
+
+def _CheckStatusFileForDuplicateKeys(filepath):
+ comma_space_bracket = re.compile(", *]")
+ lines = []
+ with open(filepath) as f:
+ for line in f.readlines():
+ # Skip all-comment lines.
+ if line.lstrip().startswith("#"): continue
+ # Strip away comments at the end of the line.
+ comment_start = line.find("#")
+ if comment_start != -1:
+ line = line[:comment_start]
+ line = line.strip()
+ # Strip away trailing commas within the line.
+ line = comma_space_bracket.sub("]", line)
+ if len(line) > 0:
+ lines.append(line)
+
+ # Strip away trailing commas at line ends. Ugh.
+ for i in range(len(lines) - 1):
+ if (lines[i].endswith(",") and len(lines[i + 1]) > 0 and
+ lines[i + 1][0] in ("}", "]")):
+ lines[i] = lines[i][:-1]
+
+ contents = "\n".join(lines)
+ # JSON wants double-quotes.
+ contents = contents.replace("'", '"')
+ # Fill in keywords (like PASS, SKIP).
+ for key in statusfile.KEYWORDS:
+ contents = re.sub(r"\b%s\b" % key, "\"%s\"" % key, contents)
+
+ status = {"success": True}
+ def check_pairs(pairs):
+ keys = {}
+ for key, value in pairs:
+ if key in keys:
+ print("%s: Error: duplicate key %s" % (filepath, key))
+ status["success"] = False
+ keys[key] = True
+
+ json.loads(contents, object_pairs_hook=check_pairs)
+ return status["success"]
+
def CheckStatusFiles(workspace):
+ success = True
suite_paths = utils.GetSuitePaths(join(workspace, "test"))
for root in suite_paths:
suite_path = join(workspace, "test", root)
@@ -415,8 +460,10 @@ def CheckStatusFiles(workspace):
suite = testsuite.TestSuite.LoadTestSuite(suite_path)
if suite and exists(status_file_path):
if not statusfile.PresubmitCheck(status_file_path):
Michael Achenbach 2015/11/27 14:24:20 suggestion: Maybe rewrite this with: success &= C
Jakob Kummerow 2015/11/27 14:43:26 Done.
- return False
- return True
+ success = False
+ if not _CheckStatusFileForDuplicateKeys(status_file_path):
+ success = False
+ return success
def CheckAuthorizedAuthor(input_api, output_api):
"""For non-googler/chromites committers, verify the author's email address is

Powered by Google App Engine
This is Rietveld 408576698