Initial commit
[yaffs-website] / node_modules / node-gyp / gyp / tools / pretty_sln.py
1 #!/usr/bin/env python
2
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.
6
7 """Prints the information in a sln file in a diffable way.
8
9    It first outputs each projects in alphabetical order with their
10    dependencies.
11
12    Then it outputs a possible build order.
13 """
14
15 __author__ = 'nsylvain (Nicolas Sylvain)'
16
17 import os
18 import re
19 import sys
20 import pretty_vcproj
21
22 def BuildProject(project, built, projects, deps):
23   # if all dependencies are done, we can build it, otherwise we try to build the
24   # dependency.
25   # This is not infinite-recursion proof.
26   for dep in deps[project]:
27     if dep not in built:
28       BuildProject(dep, built, projects, deps)
29   print project
30   built.append(project)
31
32 def ParseSolution(solution_file):
33   # All projects, their clsid and paths.
34   projects = dict()
35
36   # A list of dependencies associated with a project.
37   dependencies = dict()
38
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(' *({.*}) = ({.*})$')
52
53   in_deps = False
54   solution = open(solution_file)
55   for line in solution:
56     results = begin_project.search(line)
57     if results:
58       # Hack to remove icu because the diff is too different.
59       if results.group(1).find('icu') != -1:
60         continue
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', ''),
64                                    results.group(3),
65                                    results.group(2)]
66       dependencies[current_project] = []
67       continue
68
69     results = end_project.search(line)
70     if results:
71       current_project = None
72       continue
73
74     results = begin_dep.search(line)
75     if results:
76       in_deps = True
77       continue
78
79     results = end_dep.search(line)
80     if results:
81       in_deps = False
82       continue
83
84     results = dep_line.search(line)
85     if results and in_deps and current_project:
86       dependencies[current_project].append(results.group(1))
87       continue
88
89   # Change all dependencies clsid to name instead.
90   for project in dependencies:
91     # For each dependencies in this project
92     new_dep_array = []
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)
99
100   return (projects, dependencies)
101
102 def PrintDependencies(projects, deps):
103   print "---------------------------------------"
104   print "Dependencies for all projects"
105   print "---------------------------------------"
106   print "--                                   --"
107
108   for (project, dep_list) in sorted(deps.items()):
109     print "Project : %s" % project
110     print "Path : %s" % projects[project][0]
111     if dep_list:
112       for dep in dep_list:
113         print "  - %s" % dep
114     print ""
115
116   print "--                                   --"
117
118 def PrintBuildOrder(projects, deps):
119   print "---------------------------------------"
120   print "Build order                            "
121   print "---------------------------------------"
122   print "--                                   --"
123
124   built = []
125   for (project, _) in sorted(deps.items()):
126     if project not in built:
127       BuildProject(project, built, projects, deps)
128
129   print "--                                   --"
130
131 def PrintVCProj(projects):
132
133   for project in projects:
134     print "-------------------------------------"
135     print "-------------------------------------"
136     print project
137     print project
138     print project
139     print "-------------------------------------"
140     print "-------------------------------------"
141
142     project_path = os.path.abspath(os.path.join(os.path.dirname(sys.argv[1]),
143                                                 projects[project][2]))
144
145     pretty = pretty_vcproj
146     argv = [ '',
147              project_path,
148              '$(SolutionDir)=%s\\' % os.path.dirname(sys.argv[1]),
149            ]
150     argv.extend(sys.argv[3:])
151     pretty.main(argv)
152
153 def main():
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]
157     return 1
158
159   (projects, deps) = ParseSolution(sys.argv[1])
160   PrintDependencies(projects, deps)
161   PrintBuildOrder(projects, deps)
162
163   if '--recursive' in sys.argv:
164     PrintVCProj(projects)
165   return 0
166
167
168 if __name__ == '__main__':
169   sys.exit(main())