Matthew Iselin | 50df82f | 2016-04-06 17:01:47 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python2.7 |
| 2 | |
| 3 | # Copyright 2016, Google Inc. |
| 4 | # All rights reserved. |
| 5 | # |
| 6 | # Redistribution and use in source and binary forms, with or without |
| 7 | # modification, are permitted provided that the following conditions are |
| 8 | # met: |
| 9 | # |
| 10 | # * Redistributions of source code must retain the above copyright |
| 11 | # notice, this list of conditions and the following disclaimer. |
| 12 | # * Redistributions in binary form must reproduce the above |
| 13 | # copyright notice, this list of conditions and the following disclaimer |
| 14 | # in the documentation and/or other materials provided with the |
| 15 | # distribution. |
| 16 | # * Neither the name of Google Inc. nor the names of its |
| 17 | # contributors may be used to endorse or promote products derived from |
| 18 | # this software without specific prior written permission. |
| 19 | # |
| 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | |
| 32 | import os |
| 33 | import re |
| 34 | import sys |
| 35 | |
| 36 | from lxml import etree |
| 37 | |
| 38 | |
| 39 | def main(): |
| 40 | root_dir = os.path.abspath( |
| 41 | os.path.join(os.path.dirname(sys.argv[0]), '../..')) |
| 42 | os.chdir(root_dir) |
| 43 | |
| 44 | project_re = re.compile('Project\(.*\) = ".+", "(.+)", "(.+)"') |
| 45 | |
| 46 | known_projects = {} |
| 47 | with open(os.path.join('vsprojects', 'grpc.sln')) as f: |
| 48 | for line in f.readlines(): |
| 49 | m = project_re.match(line) |
| 50 | if not m: |
| 51 | continue |
| 52 | |
| 53 | vcxproj_path, project_guid = m.groups() |
| 54 | if os.name != 'nt': |
| 55 | vcxproj_path = vcxproj_path.replace('\\', '/') |
| 56 | |
| 57 | known_projects[project_guid] = vcxproj_path |
| 58 | |
| 59 | ok = True |
| 60 | for vcxproj_path in known_projects.values(): |
| 61 | with open(os.path.join(root_dir, 'vsprojects', vcxproj_path)) as f: |
| 62 | tree = etree.parse(f) |
| 63 | |
| 64 | namespaces = {'ns': 'http://schemas.microsoft.com/developer/msbuild/2003'} |
| 65 | referenced_projects = tree.getroot().xpath('/ns:Project/ns:ItemGroup' |
| 66 | '/ns:ProjectReference' |
| 67 | '/ns:Project', |
| 68 | namespaces=namespaces) |
| 69 | for referenced_project in referenced_projects: |
| 70 | # Project tag under ProjectReference is a GUID reference. |
| 71 | if referenced_project.text not in known_projects: |
| 72 | target_vcxproj = referenced_project.getparent().attrib['Include'] |
| 73 | guid = referenced_project.text |
| 74 | print ('In project "%s", dependency "%s" (with GUID "%s") is not in ' |
| 75 | 'grpc.sln' % (vcxproj_path, target_vcxproj, guid)) |
| 76 | ok = False |
| 77 | |
| 78 | if not ok: |
| 79 | exit(1) |
| 80 | |
| 81 | |
| 82 | if __name__ == '__main__': |
| 83 | main() |
| 84 | |