OLD | NEW |
(Empty) | |
| 1 # Copyright 2015, 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 vsprojects plugin. |
| 31 |
| 32 This parses the list of libraries, and generates globals "vsprojects" |
| 33 and "vsproject_dict", to be used by the visual studio generators. |
| 34 |
| 35 """ |
| 36 |
| 37 |
| 38 import hashlib |
| 39 import re |
| 40 |
| 41 |
| 42 def mako_plugin(dictionary): |
| 43 """The exported plugin code for generate_vsprojeccts |
| 44 |
| 45 We want to help the work of the visual studio generators. |
| 46 |
| 47 """ |
| 48 |
| 49 libs = dictionary.get('libs', []) |
| 50 targets = dictionary.get('targets', []) |
| 51 |
| 52 for lib in libs: |
| 53 lib['is_library'] = True |
| 54 for target in targets: |
| 55 target['is_library'] = False |
| 56 |
| 57 projects = [] |
| 58 projects.extend(libs) |
| 59 projects.extend(targets) |
| 60 for target in projects: |
| 61 if 'build' in target and target['build'] == 'test': |
| 62 default_test_dir = 'test' |
| 63 else: |
| 64 default_test_dir = '.' |
| 65 if 'vs_config_type' not in target: |
| 66 if 'build' in target and target['build'] == 'test': |
| 67 target['vs_config_type'] = 'Application' |
| 68 else: |
| 69 target['vs_config_type'] = 'StaticLibrary' |
| 70 if 'vs_packages' not in target: |
| 71 target['vs_packages'] = [] |
| 72 if 'vs_props' not in target: |
| 73 target['vs_props'] = [] |
| 74 target['vs_proj_dir'] = target.get('vs_proj_dir', default_test_dir) |
| 75 if target.get('vs_project_guid', None) is None and 'windows' in target.get('
platforms', ['windows']): |
| 76 name = target['name'] |
| 77 guid = re.sub('(........)(....)(....)(....)(.*)', |
| 78 r'{\1-\2-\3-\4-\5}', |
| 79 hashlib.md5(name).hexdigest()) |
| 80 target['vs_project_guid'] = guid.upper() |
| 81 # Exclude projects without a visual project guid, such as the tests. |
| 82 projects = [project for project in projects |
| 83 if project.get('vs_project_guid', None)] |
| 84 |
| 85 projects = [project for project in projects |
| 86 if project['language'] != 'c++' or project['build'] == 'all' or
project['build'] == 'protoc' or (project['language'] == 'c++' and (project['bui
ld'] == 'test' or project['build'] == 'private'))] |
| 87 |
| 88 project_dict = dict([(p['name'], p) for p in projects]) |
| 89 |
| 90 packages = dictionary.get('vspackages', []) |
| 91 packages_dict = dict([(p['name'], p) for p in packages]) |
| 92 |
| 93 dictionary['vsprojects'] = projects |
| 94 dictionary['vsproject_dict'] = project_dict |
| 95 dictionary['vspackages_dict'] = packages_dict |
OLD | NEW |