OLD | NEW |
(Empty) | |
| 1 # Copyright 2016, Google Inc. |
| 2 # All rights reserved. |
| 3 # |
| 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are |
| 6 # met: |
| 7 # |
| 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above |
| 11 # copyright notice, this list of conditions and the following disclaimer |
| 12 # in the documentation and/or other materials provided with the |
| 13 # distribution. |
| 14 # * Neither the name of Google Inc. nor the names of its |
| 15 # contributors may be used to endorse or promote products derived from |
| 16 # this software without specific prior written permission. |
| 17 # |
| 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 |
| 30 """Buildgen .proto files list plugin. |
| 31 |
| 32 This parses the list of targets from the yaml build file, and creates |
| 33 a list called "protos" that contains all of the proto file names. |
| 34 |
| 35 """ |
| 36 |
| 37 |
| 38 import re |
| 39 |
| 40 LANGUAGES = [ |
| 41 'core', |
| 42 'cpp', |
| 43 'csharp', |
| 44 'node', |
| 45 'objc', |
| 46 'php', |
| 47 'python', |
| 48 'ruby', |
| 49 ] |
| 50 |
| 51 class Version: |
| 52 |
| 53 def __init__(self, s): |
| 54 self.tag = None |
| 55 if '-' in s: |
| 56 s, self.tag = s.split('-') |
| 57 self.major, self.minor, self.patch = [int(x) for x in s.split('.')] |
| 58 |
| 59 def __str__(self): |
| 60 """Version string in a somewhat idiomatic style for most languages""" |
| 61 s = '%d.%d.%d' % (self.major, self.minor, self.patch) |
| 62 if self.tag: |
| 63 s += '-%s' % self.tag |
| 64 return s |
| 65 |
| 66 def pep440(self): |
| 67 """Version string in Python PEP440 style""" |
| 68 s = '%d.%d.%d' % (self.major, self.minor, self.patch) |
| 69 if self.tag: |
| 70 # we need to translate from grpc version tags to pep440 version |
| 71 # tags; this code is likely to be a little ad-hoc |
| 72 if self.tag == 'dev': |
| 73 s += '.dev0' |
| 74 elif len(self.tag) >= 3 and self.tag[0:3] == 'pre': |
| 75 s += 'rc%d' % int(self.tag[3:]) |
| 76 else: |
| 77 raise Exception('Don\'t know how to translate version tag "%s" to pep440
' % self.tag) |
| 78 return s |
| 79 |
| 80 def ruby(self): |
| 81 """Version string in Ruby style""" |
| 82 if self.tag: |
| 83 return '%d.%d.%d.%s' % (self.major, self.minor, self.patch, self.tag) |
| 84 else: |
| 85 return '%d.%d.%d' % (self.major, self.minor, self.patch) |
| 86 |
| 87 def mako_plugin(dictionary): |
| 88 """Expand version numbers: |
| 89 - for each language, ensure there's a language_version tag in |
| 90 settings (defaulting to the master version tag) |
| 91 - expand version strings to major, minor, patch, and tag |
| 92 """ |
| 93 |
| 94 settings = dictionary['settings'] |
| 95 master_version = Version(settings['version']) |
| 96 settings['version'] = master_version |
| 97 for language in LANGUAGES: |
| 98 version_tag = '%s_version' % language |
| 99 if version_tag in settings: |
| 100 settings[version_tag] = Version(settings[version_tag]) |
| 101 else: |
| 102 settings[version_tag] = master_version |
OLD | NEW |