forked from coreos/coreos-overlay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PRESUBMIT.py
74 lines (64 loc) · 2.52 KB
/
PRESUBMIT.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 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
import re
_EBUILD_FILES = (
r".*\.ebuild",
)
def _IsCrosWorkonEbuild(ebuild_contents):
pattern = re.compile('^ *inherit[-\._a-z0-9 ]*cros-workon')
for line in ebuild_contents:
if pattern.match(line):
return True
return False
def Check9999Updated(input_api, output_api, source_file_filter=None):
"""Checks that the 9999 ebuild was also modified."""
output = []
inconsistent = set()
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.add(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)