Mandeep Singh Baines | e9cd41e | 2010-07-26 17:26:44 -0700 | [diff] [blame^] | 1 | # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Top-level presubmit script for Chromium OS. |
| 6 | |
| 7 | See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 8 | for more details about the presubmit API built into gcl and git cl. |
| 9 | """ |
| 10 | |
| 11 | import difflib |
| 12 | import os |
| 13 | |
| 14 | _EBUILD_FILES = ( |
| 15 | r".*\.ebuild", |
| 16 | ) |
| 17 | |
| 18 | def _IsCrosWorkonEbuild(ebuild_contents): |
| 19 | return ebuild_contents.count('inherit cros-workon') > 0 |
| 20 | |
| 21 | def Check9999Updated(input_api, output_api, source_file_filter=None): |
| 22 | """Checks that the 9999 ebuild was also modified.""" |
| 23 | output = [] |
| 24 | inconsistent = [] |
| 25 | missing_9999 = set() |
| 26 | for f in input_api.AffectedSourceFiles(source_file_filter): |
| 27 | ebuild_contents = f.NewContents() |
| 28 | # only look at non-9999 |
| 29 | if f.LocalPath().endswith('-9999.ebuild'): |
| 30 | continue |
| 31 | if _IsCrosWorkonEbuild(ebuild_contents): |
| 32 | dir = os.path.dirname(f.AbsoluteLocalPath()) |
| 33 | ebuild = os.path.basename(dir) |
| 34 | devebuild_path = os.path.join(dir, ebuild + '-9999.ebuild') |
| 35 | # check if 9999 ebuild exists |
| 36 | if not os.path.isfile(devebuild_path): |
| 37 | missing_9999.add(ebuild) |
| 38 | continue |
| 39 | diff = difflib.ndiff(ebuild_contents, |
| 40 | open(devebuild_path).read().splitlines()) |
| 41 | for line in diff: |
| 42 | if line.startswith('+') or line.startswith('-'): |
| 43 | # ignore empty-lines |
| 44 | if len(line) == 2: |
| 45 | continue |
| 46 | if not (line[2:].startswith('KEYWORDS=') or |
| 47 | line[2:].startswith('CROS_WORKON_COMMIT=')): |
| 48 | inconsistent.append(f.LocalPath()) |
| 49 | |
| 50 | if missing_9999: |
| 51 | output.append(output_api.PresubmitPromptWarning( |
| 52 | 'Missing 9999 for these cros-workon ebuilds:', items=missing_9999)) |
| 53 | if inconsistent: |
| 54 | output.append(output_api.PresubmitPromptWarning( |
| 55 | 'Following ebuilds are inconsistent with 9999:', items=inconsistent)) |
| 56 | return output |
| 57 | |
| 58 | def CheckChange(input_api, output_api, committing): |
| 59 | ebuilds = lambda x: input_api.FilterSourceFile(x, white_list=_EBUILD_FILES) |
| 60 | results = [] |
| 61 | results += Check9999Updated(input_api, output_api, |
| 62 | source_file_filter=ebuilds) |
| 63 | return results |
| 64 | |
| 65 | def CheckChangeOnUpload(input_api, output_api): |
| 66 | return CheckChange(input_api, output_api, False) |
| 67 | |
| 68 | def CheckChangeOnCommit(input_api, output_api): |
| 69 | return CheckChange(input_api, output_api, True) |