Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 1 | # Copyright 2015 gRPC authors. |
Craig Tiller | c2c7921 | 2015-02-16 12:00:01 -0800 | [diff] [blame] | 2 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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 |
Craig Tiller | c2c7921 | 2015-02-16 12:00:01 -0800 | [diff] [blame] | 6 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
Craig Tiller | c2c7921 | 2015-02-16 12:00:01 -0800 | [diff] [blame] | 8 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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. |
Nicolas "Pixel" Noble | cc0994c | 2015-01-15 06:47:41 +0100 | [diff] [blame] | 14 | """Buildgen vsprojects plugin. |
| 15 | |
| 16 | This parses the list of libraries, and generates globals "vsprojects" |
| 17 | and "vsproject_dict", to be used by the visual studio generators. |
| 18 | |
| 19 | """ |
| 20 | |
Nicolas "Pixel" Noble | 7bf5092 | 2015-05-09 03:17:21 +0200 | [diff] [blame] | 21 | import hashlib |
| 22 | import re |
| 23 | |
| 24 | |
Nicolas "Pixel" Noble | cc0994c | 2015-01-15 06:47:41 +0100 | [diff] [blame] | 25 | def mako_plugin(dictionary): |
ncteisen | 26d70b1 | 2017-12-11 16:40:56 -0800 | [diff] [blame] | 26 | """The exported plugin code for generate_vsprojeccts |
Nicolas "Pixel" Noble | cc0994c | 2015-01-15 06:47:41 +0100 | [diff] [blame] | 27 | |
| 28 | We want to help the work of the visual studio generators. |
| 29 | |
| 30 | """ |
| 31 | |
ncteisen | 26d70b1 | 2017-12-11 16:40:56 -0800 | [diff] [blame] | 32 | libs = dictionary.get('libs', []) |
| 33 | targets = dictionary.get('targets', []) |
Nicolas "Pixel" Noble | cc0994c | 2015-01-15 06:47:41 +0100 | [diff] [blame] | 34 | |
ncteisen | 26d70b1 | 2017-12-11 16:40:56 -0800 | [diff] [blame] | 35 | for lib in libs: |
| 36 | lib['is_library'] = True |
| 37 | for target in targets: |
| 38 | target['is_library'] = False |
Nicolas "Pixel" Noble | cc0994c | 2015-01-15 06:47:41 +0100 | [diff] [blame] | 39 | |
ncteisen | 26d70b1 | 2017-12-11 16:40:56 -0800 | [diff] [blame] | 40 | projects = [] |
| 41 | projects.extend(libs) |
| 42 | projects.extend(targets) |
| 43 | for target in projects: |
| 44 | if 'build' in target and target['build'] == 'test': |
| 45 | default_test_dir = 'test' |
| 46 | else: |
| 47 | default_test_dir = '.' |
| 48 | if 'vs_config_type' not in target: |
| 49 | if 'build' in target and target['build'] == 'test': |
| 50 | target['vs_config_type'] = 'Application' |
| 51 | else: |
| 52 | target['vs_config_type'] = 'StaticLibrary' |
| 53 | if 'vs_packages' not in target: |
| 54 | target['vs_packages'] = [] |
| 55 | if 'vs_props' not in target: |
| 56 | target['vs_props'] = [] |
| 57 | target['vs_proj_dir'] = target.get('vs_proj_dir', default_test_dir) |
| 58 | if target.get('vs_project_guid', |
Mehrdad Afshari | 87cd994 | 2018-01-02 14:40:00 -0800 | [diff] [blame] | 59 | None) is None and 'windows' in target.get( |
| 60 | 'platforms', ['windows']): |
ncteisen | 26d70b1 | 2017-12-11 16:40:56 -0800 | [diff] [blame] | 61 | name = target['name'] |
| 62 | guid = re.sub('(........)(....)(....)(....)(.*)', |
Mehrdad Afshari | 87cd994 | 2018-01-02 14:40:00 -0800 | [diff] [blame] | 63 | r'{\1-\2-\3-\4-\5}', |
| 64 | hashlib.md5(name).hexdigest()) |
ncteisen | 26d70b1 | 2017-12-11 16:40:56 -0800 | [diff] [blame] | 65 | target['vs_project_guid'] = guid.upper() |
| 66 | # Exclude projects without a visual project guid, such as the tests. |
| 67 | projects = [ |
| 68 | project for project in projects if project.get('vs_project_guid', None) |
| 69 | ] |
Nicolas "Pixel" Noble | cc0994c | 2015-01-15 06:47:41 +0100 | [diff] [blame] | 70 | |
ncteisen | 26d70b1 | 2017-12-11 16:40:56 -0800 | [diff] [blame] | 71 | projects = [ |
| 72 | project for project in projects |
Mehrdad Afshari | 87cd994 | 2018-01-02 14:40:00 -0800 | [diff] [blame] | 73 | if project['language'] != 'c++' or project['build'] == 'all' or |
| 74 | project['build'] == 'protoc' or (project['language'] == 'c++' and ( |
| 75 | project['build'] == 'test' or project['build'] == 'private')) |
ncteisen | 26d70b1 | 2017-12-11 16:40:56 -0800 | [diff] [blame] | 76 | ] |
Nicolas "Pixel" Noble | cc0994c | 2015-01-15 06:47:41 +0100 | [diff] [blame] | 77 | |
ncteisen | 26d70b1 | 2017-12-11 16:40:56 -0800 | [diff] [blame] | 78 | project_dict = dict([(p['name'], p) for p in projects]) |
Nicolas "Pixel" Noble | cc0994c | 2015-01-15 06:47:41 +0100 | [diff] [blame] | 79 | |
ncteisen | 26d70b1 | 2017-12-11 16:40:56 -0800 | [diff] [blame] | 80 | packages = dictionary.get('vspackages', []) |
| 81 | packages_dict = dict([(p['name'], p) for p in packages]) |
Craig Tiller | 1ebb7c8 | 2015-08-31 15:53:36 -0700 | [diff] [blame] | 82 | |
ncteisen | 26d70b1 | 2017-12-11 16:40:56 -0800 | [diff] [blame] | 83 | dictionary['vsprojects'] = projects |
| 84 | dictionary['vsproject_dict'] = project_dict |
| 85 | dictionary['vspackages_dict'] = packages_dict |