Create a PRESUBMIT which verifies that 9999 and stable are in sync
BUG=4993
TEST=Verified that there is no error when in sync.
Verified that an error is reported when 9999 does not exist.
Verified that an error is reported when not in sync.
Change-Id: I734ba8bd4e83cc3eebc514bdf9ec7c73d9cbb65b
Review URL: http://codereview.chromium.org/3015033
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
new file mode 100644
index 0000000..934f466
--- /dev/null
+++ b/PRESUBMIT.py
@@ -0,0 +1,69 @@
+# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Top-level presubmit script for Chromium OS.
+
+See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
+for more details about the presubmit API built into gcl and git cl.
+"""
+
+import difflib
+import os
+
+_EBUILD_FILES = (
+ r".*\.ebuild",
+)
+
+def _IsCrosWorkonEbuild(ebuild_contents):
+ return ebuild_contents.count('inherit cros-workon') > 0
+
+def Check9999Updated(input_api, output_api, source_file_filter=None):
+ """Checks that the 9999 ebuild was also modified."""
+ output = []
+ inconsistent = []
+ missing_9999 = set()
+ for f in input_api.AffectedSourceFiles(source_file_filter):
+ ebuild_contents = f.NewContents()
+ # only look at non-9999
+ if f.LocalPath().endswith('-9999.ebuild'):
+ continue
+ if _IsCrosWorkonEbuild(ebuild_contents):
+ dir = os.path.dirname(f.AbsoluteLocalPath())
+ ebuild = os.path.basename(dir)
+ devebuild_path = os.path.join(dir, ebuild + '-9999.ebuild')
+ # check if 9999 ebuild exists
+ if not os.path.isfile(devebuild_path):
+ missing_9999.add(ebuild)
+ continue
+ diff = difflib.ndiff(ebuild_contents,
+ open(devebuild_path).read().splitlines())
+ for line in diff:
+ if line.startswith('+') or line.startswith('-'):
+ # ignore empty-lines
+ if len(line) == 2:
+ continue
+ if not (line[2:].startswith('KEYWORDS=') or
+ line[2:].startswith('CROS_WORKON_COMMIT=')):
+ inconsistent.append(f.LocalPath())
+
+ if missing_9999:
+ output.append(output_api.PresubmitPromptWarning(
+ 'Missing 9999 for these cros-workon ebuilds:', items=missing_9999))
+ if inconsistent:
+ output.append(output_api.PresubmitPromptWarning(
+ 'Following ebuilds are inconsistent with 9999:', items=inconsistent))
+ return output
+
+def CheckChange(input_api, output_api, committing):
+ ebuilds = lambda x: input_api.FilterSourceFile(x, white_list=_EBUILD_FILES)
+ results = []
+ results += Check9999Updated(input_api, output_api,
+ source_file_filter=ebuilds)
+ return results
+
+def CheckChangeOnUpload(input_api, output_api):
+ return CheckChange(input_api, output_api, False)
+
+def CheckChangeOnCommit(input_api, output_api):
+ return CheckChange(input_api, output_api, True)