Index: PRESUBMIT.py |
diff --git a/PRESUBMIT.py b/PRESUBMIT.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..934f4660fd47132d512b9a0d1ae03689596d295b |
--- /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 |
sosa
2010/07/27 00:30:38
What happens if an ebuild contains "inherit someth
|
+ |
+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') |
Chris Masone
2010/07/26 22:23:33
will this work if I have chromeos-login-0.5.0.ebui
|
+ # 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) |