blob: 41dd5efe3887fde41b69aa70e2add1d876ec4161 [file] [log] [blame]
Craig Tiller95e81872016-02-08 15:48:55 -08001#!/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
32import sys
33import yaml
34import os
35import re
36import subprocess
37
38errors = 0
39
40os.chdir(os.path.join(os.path.dirname(sys.argv[0]), '../../..'))
41
42# hack import paths to pick up extra code
43sys.path.insert(0, os.path.abspath('tools/buildgen/plugins'))
44from expand_version import Version
45
46try:
47 branch_name = subprocess.check_output(
48 'git rev-parse --abbrev-ref HEAD',
49 shell=True)
50except:
51 print 'WARNING: not a git repository'
52 branch_name = None
53
54if 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'
70else:
71 check_version = lambda version: True
72
73with open('build.yaml', 'r') as f:
74 build_yaml = yaml.load(f.read())
75
76settings = build_yaml['settings']
77
78top_version = Version(settings['version'])
79if not check_version(top_version):
80 errors += 1
81 print warning % ('version', top_version)
82
83for 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
96sys.exit(errors)
97