Craig Tiller | 95e8187 | 2016-02-08 15:48:55 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python2.7 |
| 2 | |
| 3 | # Copyright 2016, Google Inc. |
| 4 | # All rights reserved. |
| 5 | # |
| 6 | # Redistribution and use in source and binary forms, with or without |
| 7 | # modification, are permitted provided that the following conditions are |
| 8 | # met: |
| 9 | # |
| 10 | # * Redistributions of source code must retain the above copyright |
| 11 | # notice, this list of conditions and the following disclaimer. |
| 12 | # * Redistributions in binary form must reproduce the above |
| 13 | # copyright notice, this list of conditions and the following disclaimer |
| 14 | # in the documentation and/or other materials provided with the |
| 15 | # distribution. |
| 16 | # * Neither the name of Google Inc. nor the names of its |
| 17 | # contributors may be used to endorse or promote products derived from |
| 18 | # this software without specific prior written permission. |
| 19 | # |
| 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | |
| 32 | import sys |
| 33 | import yaml |
| 34 | import os |
| 35 | import re |
| 36 | import subprocess |
| 37 | |
| 38 | errors = 0 |
| 39 | |
| 40 | os.chdir(os.path.join(os.path.dirname(sys.argv[0]), '../../..')) |
| 41 | |
| 42 | # hack import paths to pick up extra code |
| 43 | sys.path.insert(0, os.path.abspath('tools/buildgen/plugins')) |
| 44 | from expand_version import Version |
| 45 | |
| 46 | try: |
| 47 | branch_name = subprocess.check_output( |
| 48 | 'git rev-parse --abbrev-ref HEAD', |
| 49 | shell=True) |
| 50 | except: |
| 51 | print 'WARNING: not a git repository' |
| 52 | branch_name = None |
| 53 | |
| 54 | if branch_name is not None: |
| 55 | m = re.match(r'^release-([0-9]+)_([0-9]+)$', branch_name) |
| 56 | if m: |
| 57 | print 'RELEASE branch' |
| 58 | # version number should align with the branched version |
| 59 | check_version = lambda version: ( |
| 60 | version.major == int(m.group(1)) and |
| 61 | version.minor == int(m.group(2))) |
| 62 | warning = 'Version key "%%s" value "%%s" should have a major version %s and minor version %s' % (m.group(1), m.group(2)) |
| 63 | elif re.match(r'^debian/.*$', branch_name): |
| 64 | # no additional version checks for debian branches |
| 65 | check_version = lambda version: True |
| 66 | else: |
| 67 | # all other branches should have a -dev tag |
| 68 | check_version = lambda version: version.tag == 'dev' |
| 69 | warning = 'Version key "%s" value "%s" should have a -dev tag' |
| 70 | else: |
| 71 | check_version = lambda version: True |
| 72 | |
| 73 | with open('build.yaml', 'r') as f: |
| 74 | build_yaml = yaml.load(f.read()) |
| 75 | |
| 76 | settings = build_yaml['settings'] |
| 77 | |
| 78 | top_version = Version(settings['version']) |
| 79 | if not check_version(top_version): |
| 80 | errors += 1 |
| 81 | print warning % ('version', top_version) |
| 82 | |
| 83 | for tag, value in settings.iteritems(): |
| 84 | if re.match(r'^[a-z]+_version$', tag): |
| 85 | value = Version(value) |
| 86 | if value.major != top_version.major: |
| 87 | errors += 1 |
| 88 | print 'major version mismatch on %s: %d vs %d' % (tag, value.major, top_version.major) |
| 89 | if value.minor != top_version.minor: |
| 90 | errors += 1 |
| 91 | print 'minor version mismatch on %s: %d vs %d' % (tag, value.minor, top_version.minor) |
| 92 | if not check_version(value): |
| 93 | errors += 1 |
| 94 | print warning % (tag, value) |
| 95 | |
| 96 | sys.exit(errors) |
| 97 | |