1#!/usr/bin/env python 2 3# Copyright 2016 gRPC authors. 4# 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 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 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. 16 17from __future__ import print_function 18 19import sys 20import yaml 21import os 22import re 23import subprocess 24 25errors = 0 26 27os.chdir(os.path.join(os.path.dirname(sys.argv[0]), '../../..')) 28 29# hack import paths to pick up extra code 30sys.path.insert(0, os.path.abspath('tools/buildgen/plugins')) 31from expand_version import Version 32 33try: 34 branch_name = subprocess.check_output('git rev-parse --abbrev-ref HEAD', 35 shell=True) 36except: 37 print('WARNING: not a git repository') 38 branch_name = None 39 40if branch_name is not None: 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: (version.major == int(m.group(1)) and 46 version.minor == int(m.group(2))) 47 warning = 'Version key "%%s" value "%%s" should have a major version %s and minor version %s' % ( 48 m.group(1), m.group(2)) 49 elif re.match(r'^debian/.*$', branch_name): 50 # no additional version checks for debian branches 51 check_version = lambda version: True 52 else: 53 # all other branches should have a -dev tag 54 check_version = lambda version: version.tag == 'dev' 55 warning = 'Version key "%s" value "%s" should have a -dev tag' 56else: 57 check_version = lambda version: True 58 59with open('build_handwritten.yaml', 'r') as f: 60 build_yaml = yaml.load(f.read()) 61 62settings = build_yaml['settings'] 63 64top_version = Version(settings['version']) 65if not check_version(top_version): 66 errors += 1 67 print(warning % ('version', top_version)) 68 69for tag, value in settings.iteritems(): 70 if re.match(r'^[a-z]+_version$', tag): 71 value = Version(value) 72 if tag != 'core_version': 73 if value.major != top_version.major: 74 errors += 1 75 print('major version mismatch on %s: %d vs %d' % 76 (tag, value.major, top_version.major)) 77 if value.minor != top_version.minor: 78 errors += 1 79 print('minor version mismatch on %s: %d vs %d' % 80 (tag, value.minor, top_version.minor)) 81 if not check_version(value): 82 errors += 1 83 print(warning % (tag, value)) 84 85sys.exit(errors) 86