blob: f7ef49288f2588b951df431093d018d8071dc73a [file] [log] [blame]
Jan Tattermusch7897ae92017-06-07 22:57:36 +02001# Copyright 2015 gRPC authors.
Craig Tillerc2c79212015-02-16 12:00:01 -08002#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003# 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 Tillerc2c79212015-02-16 12:00:01 -08006#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02007# http://www.apache.org/licenses/LICENSE-2.0
Craig Tillerc2c79212015-02-16 12:00:01 -08008#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009# 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" Noblecc0994c2015-01-15 06:47:41 +010014"""Buildgen vsprojects plugin.
15
16This parses the list of libraries, and generates globals "vsprojects"
17and "vsproject_dict", to be used by the visual studio generators.
18
19"""
20
Nicolas "Pixel" Noble7bf50922015-05-09 03:17:21 +020021import hashlib
22import re
23
24
Nicolas "Pixel" Noblecc0994c2015-01-15 06:47:41 +010025def mako_plugin(dictionary):
ncteisen26d70b12017-12-11 16:40:56 -080026 """The exported plugin code for generate_vsprojeccts
Nicolas "Pixel" Noblecc0994c2015-01-15 06:47:41 +010027
28 We want to help the work of the visual studio generators.
29
30 """
31
ncteisen26d70b12017-12-11 16:40:56 -080032 libs = dictionary.get('libs', [])
33 targets = dictionary.get('targets', [])
Nicolas "Pixel" Noblecc0994c2015-01-15 06:47:41 +010034
ncteisen26d70b12017-12-11 16:40:56 -080035 for lib in libs:
36 lib['is_library'] = True
37 for target in targets:
38 target['is_library'] = False
Nicolas "Pixel" Noblecc0994c2015-01-15 06:47:41 +010039
ncteisen26d70b12017-12-11 16:40:56 -080040 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 Afshari87cd9942018-01-02 14:40:00 -080059 None) is None and 'windows' in target.get(
60 'platforms', ['windows']):
ncteisen26d70b12017-12-11 16:40:56 -080061 name = target['name']
62 guid = re.sub('(........)(....)(....)(....)(.*)',
Mehrdad Afshari87cd9942018-01-02 14:40:00 -080063 r'{\1-\2-\3-\4-\5}',
64 hashlib.md5(name).hexdigest())
ncteisen26d70b12017-12-11 16:40:56 -080065 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" Noblecc0994c2015-01-15 06:47:41 +010070
ncteisen26d70b12017-12-11 16:40:56 -080071 projects = [
72 project for project in projects
Mehrdad Afshari87cd9942018-01-02 14:40:00 -080073 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'))
ncteisen26d70b12017-12-11 16:40:56 -080076 ]
Nicolas "Pixel" Noblecc0994c2015-01-15 06:47:41 +010077
ncteisen26d70b12017-12-11 16:40:56 -080078 project_dict = dict([(p['name'], p) for p in projects])
Nicolas "Pixel" Noblecc0994c2015-01-15 06:47:41 +010079
ncteisen26d70b12017-12-11 16:40:56 -080080 packages = dictionary.get('vspackages', [])
81 packages_dict = dict([(p['name'], p) for p in packages])
Craig Tiller1ebb7c82015-08-31 15:53:36 -070082
ncteisen26d70b12017-12-11 16:40:56 -080083 dictionary['vsprojects'] = projects
84 dictionary['vsproject_dict'] = project_dict
85 dictionary['vspackages_dict'] = packages_dict