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
5 # found in the LICENSE file.
7 """Prints the information in a sln file in a diffable way.
9 It first outputs each projects in alphabetical order with their
12 Then it outputs a possible build order.
15 __author__ = 'nsylvain (Nicolas Sylvain)'
22 def BuildProject(project, built, projects, deps):
23 # if all dependencies are done, we can build it, otherwise we try to build the
25 # This is not infinite-recursion proof.
26 for dep in deps[project]:
28 BuildProject(dep, built, projects, deps)
32 def ParseSolution(solution_file):
33 # All projects, their clsid and paths.
36 # A list of dependencies associated with a project.
39 # Regular expressions that matches the SLN format.
40 # The first line of a project definition.
41 begin_project = re.compile(r'^Project\("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942'
42 r'}"\) = "(.*)", "(.*)", "(.*)"$')
43 # The last line of a project definition.
44 end_project = re.compile('^EndProject$')
45 # The first line of a dependency list.
46 begin_dep = re.compile(
47 r'ProjectSection\(ProjectDependencies\) = postProject$')
48 # The last line of a dependency list.
49 end_dep = re.compile('EndProjectSection$')
50 # A line describing a dependency.
51 dep_line = re.compile(' *({.*}) = ({.*})$')
54 solution = open(solution_file)
56 results = begin_project.search(line)
58 # Hack to remove icu because the diff is too different.
59 if results.group(1).find('icu') != -1:
61 # We remove "_gyp" from the names because it helps to diff them.
62 current_project = results.group(1).replace('_gyp', '')
63 projects[current_project] = [results.group(2).replace('_gyp', ''),
66 dependencies[current_project] = []
69 results = end_project.search(line)
71 current_project = None
74 results = begin_dep.search(line)
79 results = end_dep.search(line)
84 results = dep_line.search(line)
85 if results and in_deps and current_project:
86 dependencies[current_project].append(results.group(1))
89 # Change all dependencies clsid to name instead.
90 for project in dependencies:
91 # For each dependencies in this project
93 for dep in dependencies[project]:
94 # Look for the project name matching this cldis
95 for project_info in projects:
96 if projects[project_info][1] == dep:
97 new_dep_array.append(project_info)
98 dependencies[project] = sorted(new_dep_array)
100 return (projects, dependencies)
102 def PrintDependencies(projects, deps):
103 print "---------------------------------------"
104 print "Dependencies for all projects"
105 print "---------------------------------------"
108 for (project, dep_list) in sorted(deps.items()):
109 print "Project : %s" % project
110 print "Path : %s" % projects[project][0]
118 def PrintBuildOrder(projects, deps):
119 print "---------------------------------------"
121 print "---------------------------------------"
125 for (project, _) in sorted(deps.items()):
126 if project not in built:
127 BuildProject(project, built, projects, deps)
131 def PrintVCProj(projects):
133 for project in projects:
134 print "-------------------------------------"
135 print "-------------------------------------"
139 print "-------------------------------------"
140 print "-------------------------------------"
142 project_path = os.path.abspath(os.path.join(os.path.dirname(sys.argv[1]),
143 projects[project][2]))
145 pretty = pretty_vcproj
148 '$(SolutionDir)=%s\\' % os.path.dirname(sys.argv[1]),
150 argv.extend(sys.argv[3:])
154 # check if we have exactly 1 parameter.
155 if len(sys.argv) < 2:
156 print 'Usage: %s "c:\\path\\to\\project.sln"' % sys.argv[0]
159 (projects, deps) = ParseSolution(sys.argv[1])
160 PrintDependencies(projects, deps)
161 PrintBuildOrder(projects, deps)
163 if '--recursive' in sys.argv:
164 PrintVCProj(projects)
168 if __name__ == '__main__':