Siddharth Shukla | 8e64d90 | 2017-03-12 19:50:18 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
Craig Tiller | 95e8187 | 2016-02-08 15:48:55 -0800 | [diff] [blame] | 2 | |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | # Copyright 2016 gRPC authors. |
Craig Tiller | 95e8187 | 2016-02-08 15:48:55 -0800 | [diff] [blame] | 4 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
Craig Tiller | 95e8187 | 2016-02-08 15:48:55 -0800 | [diff] [blame] | 8 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
Craig Tiller | 95e8187 | 2016-02-08 15:48:55 -0800 | [diff] [blame] | 10 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
Craig Tiller | 95e8187 | 2016-02-08 15:48:55 -0800 | [diff] [blame] | 16 | |
Siddharth Shukla | d194f59 | 2017-03-11 19:12:43 +0100 | [diff] [blame] | 17 | from __future__ import print_function |
| 18 | |
Craig Tiller | 95e8187 | 2016-02-08 15:48:55 -0800 | [diff] [blame] | 19 | import sys |
| 20 | import yaml |
| 21 | import os |
| 22 | import re |
| 23 | import subprocess |
| 24 | |
| 25 | errors = 0 |
| 26 | |
| 27 | os.chdir(os.path.join(os.path.dirname(sys.argv[0]), '../../..')) |
| 28 | |
| 29 | # hack import paths to pick up extra code |
| 30 | sys.path.insert(0, os.path.abspath('tools/buildgen/plugins')) |
| 31 | from expand_version import Version |
| 32 | |
| 33 | try: |
ncteisen | 0cd6cfe | 2017-12-11 16:56:44 -0800 | [diff] [blame] | 34 | branch_name = subprocess.check_output( |
| 35 | 'git rev-parse --abbrev-ref HEAD', shell=True) |
Craig Tiller | 95e8187 | 2016-02-08 15:48:55 -0800 | [diff] [blame] | 36 | except: |
ncteisen | 0cd6cfe | 2017-12-11 16:56:44 -0800 | [diff] [blame] | 37 | print('WARNING: not a git repository') |
| 38 | branch_name = None |
Craig Tiller | 95e8187 | 2016-02-08 15:48:55 -0800 | [diff] [blame] | 39 | |
| 40 | if branch_name is not None: |
ncteisen | 0cd6cfe | 2017-12-11 16:56:44 -0800 | [diff] [blame] | 41 | m = re.match(r'^release-([0-9]+)_([0-9]+)$', branch_name) |
| 42 | if m: |
| 43 | print('RELEASE branch') |
| 44 | # version number should align with the branched version |
| 45 | check_version = lambda version: ( |
| 46 | version.major == int(m.group(1)) and |
| 47 | version.minor == int(m.group(2))) |
| 48 | warning = 'Version key "%%s" value "%%s" should have a major version %s and minor version %s' % ( |
| 49 | m.group(1), m.group(2)) |
| 50 | elif re.match(r'^debian/.*$', branch_name): |
| 51 | # no additional version checks for debian branches |
| 52 | check_version = lambda version: True |
| 53 | else: |
| 54 | # all other branches should have a -dev tag |
| 55 | check_version = lambda version: version.tag == 'dev' |
| 56 | warning = 'Version key "%s" value "%s" should have a -dev tag' |
Craig Tiller | 95e8187 | 2016-02-08 15:48:55 -0800 | [diff] [blame] | 57 | else: |
ncteisen | 0cd6cfe | 2017-12-11 16:56:44 -0800 | [diff] [blame] | 58 | check_version = lambda version: True |
Craig Tiller | 95e8187 | 2016-02-08 15:48:55 -0800 | [diff] [blame] | 59 | |
| 60 | with open('build.yaml', 'r') as f: |
ncteisen | 0cd6cfe | 2017-12-11 16:56:44 -0800 | [diff] [blame] | 61 | build_yaml = yaml.load(f.read()) |
Craig Tiller | 95e8187 | 2016-02-08 15:48:55 -0800 | [diff] [blame] | 62 | |
| 63 | settings = build_yaml['settings'] |
| 64 | |
| 65 | top_version = Version(settings['version']) |
| 66 | if not check_version(top_version): |
ncteisen | 0cd6cfe | 2017-12-11 16:56:44 -0800 | [diff] [blame] | 67 | errors += 1 |
| 68 | print(warning % ('version', top_version)) |
Craig Tiller | 95e8187 | 2016-02-08 15:48:55 -0800 | [diff] [blame] | 69 | |
| 70 | for tag, value in settings.iteritems(): |
ncteisen | 0cd6cfe | 2017-12-11 16:56:44 -0800 | [diff] [blame] | 71 | if re.match(r'^[a-z]+_version$', tag): |
| 72 | value = Version(value) |
| 73 | if tag != 'core_version': |
| 74 | if value.major != top_version.major: |
| 75 | errors += 1 |
| 76 | print('major version mismatch on %s: %d vs %d' % |
| 77 | (tag, value.major, top_version.major)) |
| 78 | if value.minor != top_version.minor: |
| 79 | errors += 1 |
| 80 | print('minor version mismatch on %s: %d vs %d' % |
| 81 | (tag, value.minor, top_version.minor)) |
| 82 | if not check_version(value): |
| 83 | errors += 1 |
| 84 | print(warning % (tag, value)) |
Craig Tiller | 95e8187 | 2016-02-08 15:48:55 -0800 | [diff] [blame] | 85 | |
| 86 | sys.exit(errors) |