OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright (c) 2012 Google Inc. All rights reserved. | 3 # Copyright (c) 2012 Google Inc. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Prints the information in a sln file in a diffable way. | 7 """Prints the information in a sln file in a diffable way. |
8 | 8 |
9 It first outputs each projects in alphabetical order with their | 9 It first outputs each projects in alphabetical order with their |
10 dependencies. | 10 dependencies. |
11 | 11 |
12 Then it outputs a possible build order. | 12 Then it outputs a possible build order. |
13 """ | 13 """ |
14 | 14 |
| 15 from __future__ import print_function |
| 16 |
15 __author__ = 'nsylvain (Nicolas Sylvain)' | 17 __author__ = 'nsylvain (Nicolas Sylvain)' |
16 | 18 |
17 import os | 19 import os |
18 import re | 20 import re |
19 import sys | 21 import sys |
20 import pretty_vcproj | 22 import pretty_vcproj |
21 | 23 |
22 def BuildProject(project, built, projects, deps): | 24 def BuildProject(project, built, projects, deps): |
23 # if all dependencies are done, we can build it, otherwise we try to build the | 25 # if all dependencies are done, we can build it, otherwise we try to build the |
24 # dependency. | 26 # dependency. |
25 # This is not infinite-recursion proof. | 27 # This is not infinite-recursion proof. |
26 for dep in deps[project]: | 28 for dep in deps[project]: |
27 if dep not in built: | 29 if dep not in built: |
28 BuildProject(dep, built, projects, deps) | 30 BuildProject(dep, built, projects, deps) |
29 print project | 31 print(project) |
30 built.append(project) | 32 built.append(project) |
31 | 33 |
32 def ParseSolution(solution_file): | 34 def ParseSolution(solution_file): |
33 # All projects, their clsid and paths. | 35 # All projects, their clsid and paths. |
34 projects = dict() | 36 projects = dict() |
35 | 37 |
36 # A list of dependencies associated with a project. | 38 # A list of dependencies associated with a project. |
37 dependencies = dict() | 39 dependencies = dict() |
38 | 40 |
39 # Regular expressions that matches the SLN format. | 41 # Regular expressions that matches the SLN format. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 for dep in dependencies[project]: | 95 for dep in dependencies[project]: |
94 # Look for the project name matching this cldis | 96 # Look for the project name matching this cldis |
95 for project_info in projects: | 97 for project_info in projects: |
96 if projects[project_info][1] == dep: | 98 if projects[project_info][1] == dep: |
97 new_dep_array.append(project_info) | 99 new_dep_array.append(project_info) |
98 dependencies[project] = sorted(new_dep_array) | 100 dependencies[project] = sorted(new_dep_array) |
99 | 101 |
100 return (projects, dependencies) | 102 return (projects, dependencies) |
101 | 103 |
102 def PrintDependencies(projects, deps): | 104 def PrintDependencies(projects, deps): |
103 print "---------------------------------------" | 105 print("---------------------------------------") |
104 print "Dependencies for all projects" | 106 print("Dependencies for all projects") |
105 print "---------------------------------------" | 107 print("---------------------------------------") |
106 print "-- --" | 108 print("-- --") |
107 | 109 |
108 for (project, dep_list) in sorted(deps.items()): | 110 for (project, dep_list) in sorted(deps.items()): |
109 print "Project : %s" % project | 111 print("Project : %s" % project) |
110 print "Path : %s" % projects[project][0] | 112 print("Path : %s" % projects[project][0]) |
111 if dep_list: | 113 if dep_list: |
112 for dep in dep_list: | 114 for dep in dep_list: |
113 print " - %s" % dep | 115 print(" - %s" % dep) |
114 print "" | 116 print("") |
115 | 117 |
116 print "-- --" | 118 print("-- --") |
117 | 119 |
118 def PrintBuildOrder(projects, deps): | 120 def PrintBuildOrder(projects, deps): |
119 print "---------------------------------------" | 121 print("---------------------------------------") |
120 print "Build order " | 122 print("Build order ") |
121 print "---------------------------------------" | 123 print("---------------------------------------") |
122 print "-- --" | 124 print("-- --") |
123 | 125 |
124 built = [] | 126 built = [] |
125 for (project, _) in sorted(deps.items()): | 127 for (project, _) in sorted(deps.items()): |
126 if project not in built: | 128 if project not in built: |
127 BuildProject(project, built, projects, deps) | 129 BuildProject(project, built, projects, deps) |
128 | 130 |
129 print "-- --" | 131 print("-- --") |
130 | 132 |
131 def PrintVCProj(projects): | 133 def PrintVCProj(projects): |
132 | 134 |
133 for project in projects: | 135 for project in projects: |
134 print "-------------------------------------" | 136 print("-------------------------------------") |
135 print "-------------------------------------" | 137 print("-------------------------------------") |
136 print project | 138 print(project) |
137 print project | 139 print(project) |
138 print project | 140 print(project) |
139 print "-------------------------------------" | 141 print("-------------------------------------") |
140 print "-------------------------------------" | 142 print("-------------------------------------") |
141 | 143 |
142 project_path = os.path.abspath(os.path.join(os.path.dirname(sys.argv[1]), | 144 project_path = os.path.abspath(os.path.join(os.path.dirname(sys.argv[1]), |
143 projects[project][2])) | 145 projects[project][2])) |
144 | 146 |
145 pretty = pretty_vcproj | 147 pretty = pretty_vcproj |
146 argv = [ '', | 148 argv = [ '', |
147 project_path, | 149 project_path, |
148 '$(SolutionDir)=%s\\' % os.path.dirname(sys.argv[1]), | 150 '$(SolutionDir)=%s\\' % os.path.dirname(sys.argv[1]), |
149 ] | 151 ] |
150 argv.extend(sys.argv[3:]) | 152 argv.extend(sys.argv[3:]) |
151 pretty.main(argv) | 153 pretty.main(argv) |
152 | 154 |
153 def main(): | 155 def main(): |
154 # check if we have exactly 1 parameter. | 156 # check if we have exactly 1 parameter. |
155 if len(sys.argv) < 2: | 157 if len(sys.argv) < 2: |
156 print 'Usage: %s "c:\\path\\to\\project.sln"' % sys.argv[0] | 158 print('Usage: %s "c:\\path\\to\\project.sln"' % sys.argv[0]) |
157 return 1 | 159 return 1 |
158 | 160 |
159 (projects, deps) = ParseSolution(sys.argv[1]) | 161 (projects, deps) = ParseSolution(sys.argv[1]) |
160 PrintDependencies(projects, deps) | 162 PrintDependencies(projects, deps) |
161 PrintBuildOrder(projects, deps) | 163 PrintBuildOrder(projects, deps) |
162 | 164 |
163 if '--recursive' in sys.argv: | 165 if '--recursive' in sys.argv: |
164 PrintVCProj(projects) | 166 PrintVCProj(projects) |
165 return 0 | 167 return 0 |
166 | 168 |
167 | 169 |
168 if __name__ == '__main__': | 170 if __name__ == '__main__': |
169 sys.exit(main()) | 171 sys.exit(main()) |
OLD | NEW |