1 # Copyright 2016 gRPC authors.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 """Buildgen package version plugin
16 This parses the list of targets from the yaml build file, and creates
17 a custom version string for each language's package.
37 def __init__(self, version_str, override_major=None):
39 if '-' in version_str:
40 version_str, self.tag = version_str.split('-')
41 self.major, self.minor, self.patch = [
42 int(x) for x in version_str.split('.')
45 self.major = override_major
48 """Version string in a somewhat idiomatic style for most languages"""
49 version_str = '%d.%d.%d' % (self.major, self.minor, self.patch)
51 version_str += '-%s' % self.tag
55 """Version string in Python PEP440 style"""
56 s = '%d.%d.%d' % (self.major, self.minor, self.patch)
58 # we need to translate from grpc version tags to pep440 version
59 # tags; this code is likely to be a little ad-hoc
62 elif len(self.tag) >= 3 and self.tag[0:3] == 'pre':
63 s += 'rc%d' % int(self.tag[3:])
66 'Don\'t know how to translate version tag "%s" to pep440' %
71 """Version string in Ruby style"""
73 return '%d.%d.%d.%s' % (self.major, self.minor, self.patch,
76 return '%d.%d.%d' % (self.major, self.minor, self.patch)
79 """Version string for PHP PECL package"""
80 s = '%d.%d.%d' % (self.major, self.minor, self.patch)
84 elif len(self.tag) >= 3 and self.tag[0:3] == 'pre':
85 s += 'RC%d' % int(self.tag[3:])
88 'Don\'t know how to translate version tag "%s" to PECL version'
92 def php_stability(self):
93 """stability string for PHP PECL package.xml file"""
99 def php_composer(self):
100 """Version string for PHP Composer package"""
101 return '%d.%d.%d' % (self.major, self.minor, self.patch)
103 def php_current_version(self):
106 def php_debian_version(self):
110 def mako_plugin(dictionary):
111 """Expand version numbers:
112 - for each language, ensure there's a language_version tag in
113 settings (defaulting to the master version tag)
114 - expand version strings to major, minor, patch, and tag
117 settings = dictionary['settings']
118 version_str = settings['version']
119 master_version = Version(version_str)
120 settings['version'] = master_version
121 for language in LANGUAGES:
122 version_tag = '%s_version' % language
123 override_major = settings.get('%s_major_version' % language, None)
124 if version_tag in settings:
125 settings[version_tag] = Version(settings[version_tag],
126 override_major=override_major)
128 settings[version_tag] = Version(version_str,
129 override_major=override_major)