|
1 #!/usr/bin/python |
|
2 |
|
3 # Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved. |
|
4 # |
|
5 # Redistribution and use in source and binary forms, with or without |
|
6 # modification, are permitted provided that the following conditions |
|
7 # are met: |
|
8 # |
|
9 # 1. Redistributions of source code must retain the above copyright |
|
10 # notice, this list of conditions and the following disclaimer. |
|
11 # 2. Redistributions in binary form must reproduce the above copyright |
|
12 # notice, this list of conditions and the following disclaimer in the |
|
13 # documentation and/or other materials provided with the distribution. |
|
14 # 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
|
15 # its contributors may be used to endorse or promote products derived |
|
16 # from this software without specific prior written permission. |
|
17 # |
|
18 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
|
19 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
20 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
21 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
|
22 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
23 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
24 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|
25 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|
27 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
28 |
|
29 # A script to make sure the source file list for the Bakefiles is up-to-date |
|
30 # with the MSVC project files. |
|
31 |
|
32 import sys, os |
|
33 from xml.dom import minidom |
|
34 |
|
35 WebKitRoot = ".." |
|
36 |
|
37 |
|
38 class MSVS8Compiler: |
|
39 def __init__(self): |
|
40 self.precomp_headers = True |
|
41 self.warning_level = "default" |
|
42 self.defines = [] |
|
43 self.includes = [] |
|
44 |
|
45 def fromXML(self, tool): |
|
46 if tool.attributes.has_key("AdditionalIncludeDirectories"): |
|
47 includes_string = tool.attributes["AdditionalIncludeDirectories"].value |
|
48 includes_string = includes_string.replace(""", '"') |
|
49 includes_string = includes_string.replace("$", "$(DOLLAR)") |
|
50 self.includes = includes_string.split(";") |
|
51 |
|
52 if tool.attributes.has_key("PreprocessorDefinitions"): |
|
53 self.defines = tool.attributes["PreprocessorDefinitions"].value.split(";") |
|
54 |
|
55 class MSVS8Config: |
|
56 def __init__(self): |
|
57 self.target_type="exe" |
|
58 self.target_name="Release" |
|
59 self.output_dir = "" |
|
60 self.build_dir = "" |
|
61 self.pre_build_step = "" |
|
62 self.compiler = MSVS8Compiler() |
|
63 |
|
64 def fromXML(self, config): |
|
65 if config.attributes.has_key("Name"): |
|
66 self.target_name = config.attributes["Name"].value |
|
67 |
|
68 config_type = config.attributes["ConfigurationType"].value |
|
69 if config_type == "1": |
|
70 self.target_type = "exe" |
|
71 elif config_type == "2": |
|
72 self.target_type = "dll" |
|
73 elif config_type == "4": |
|
74 self.target_type = "lib" |
|
75 else: |
|
76 print "Unknown project type %s. Exiting..." % (config_type) |
|
77 sys.exit(1) |
|
78 |
|
79 tools = config.getElementsByTagName("Tool") |
|
80 |
|
81 for tool in tools: |
|
82 if tool.attributes.has_key("Name") and tool.attributes["Name"].value == "VCPreBuildEventTool" and tool.attributes.has_key("VCPreBuildEventTool"): |
|
83 self.pre_build_step = tool.attributes["VCPreBuildEventTool"].value |
|
84 continue |
|
85 |
|
86 if tool.attributes.has_key("Name") and tool.attributes["Name"].value == "VCCLCompilerTool": |
|
87 self.compiler.fromXML(tool) |
|
88 |
|
89 def asBkl(self, doc): |
|
90 target = doc.createElement(self.target_type) |
|
91 target.setAttribute("id", self.target_name) |
|
92 |
|
93 return target |
|
94 |
|
95 class MSVS8Filter: |
|
96 def __init__(self): |
|
97 self.files = [] |
|
98 self.name = "" |
|
99 self.varname = "" |
|
100 self.prefix = "WEBCORE_" |
|
101 |
|
102 def fromXML(self, filter): |
|
103 if filter.attributes.has_key("Name"): |
|
104 self.name = filter.attributes["Name"].value |
|
105 self.varname = self.prefix + "SOURCES_" + self.name.upper() |
|
106 |
|
107 for node in filter.childNodes: |
|
108 if node.nodeName == "File" and node.attributes.has_key("RelativePath"): |
|
109 filename = node.attributes["RelativePath"].value.replace("$", "$(DOLLAR)") |
|
110 filename = filename.replace("\\", "/") |
|
111 filename = "\t\t" + filename.replace("../../", "") |
|
112 if os.path.splitext(filename)[1] in [".c", ".cpp"]: |
|
113 self.files.append(filename) |
|
114 |
|
115 def asBkl(self, doc): |
|
116 sources = doc.createElement("set") |
|
117 if self.name != "": |
|
118 sources.setAttribute("var", self.varname) |
|
119 # currently we 'flatten' the MSVC sources hierarchy to a simple list |
|
120 # so we may end up with duplicates for self.varname when the root |
|
121 # and subfolders share the same name. For now, just make sure the |
|
122 # sources are added together as part of the target |
|
123 sources.setAttribute("append", "1") |
|
124 |
|
125 sources_text = "\n" |
|
126 for afile in self.files: |
|
127 sources_text += afile + "\n" |
|
128 |
|
129 sources.appendChild(doc.createTextNode(sources_text)) |
|
130 return sources |
|
131 |
|
132 class MSVS8Project: |
|
133 def __init__(self): |
|
134 self.configs = [] |
|
135 self.file_list = [] |
|
136 self.prefix = "WEBCORE_" |
|
137 |
|
138 def loadFromXML(self, filename): |
|
139 doc = minidom.parse(filename) |
|
140 configs = doc.getElementsByTagName("Configuration") |
|
141 for config in configs: |
|
142 config_obj = MSVS8Config() |
|
143 config_obj.fromXML(config) |
|
144 self.configs.append(config_obj) |
|
145 |
|
146 if filename.find("JavaScriptCore") != -1: |
|
147 self.prefix = "JSCORE_" |
|
148 |
|
149 files = doc.getElementsByTagName("Filter") |
|
150 for node in files: |
|
151 files = MSVS8Filter() |
|
152 files.prefix = self.prefix |
|
153 files.fromXML(node) |
|
154 self.file_list.append(files) |
|
155 |
|
156 def saveAsBkl(self, filename): |
|
157 doc = minidom.Document() |
|
158 makefile = doc.createElement("makefile") |
|
159 source_tags = [] |
|
160 for files in self.file_list: |
|
161 makefile.appendChild(files.asBkl(doc)) |
|
162 |
|
163 doc.appendChild(makefile) |
|
164 |
|
165 outfile = open(filename, "w") |
|
166 outfile.write(doc.toprettyxml()) |
|
167 outfile.close() |
|
168 |
|
169 jsdir = os.path.join(WebKitRoot, "JavaScriptCore") |
|
170 wcdir = os.path.join(WebKitRoot, "WebCore") |
|
171 |
|
172 files = { jsdir: os.path.join(jsdir, "JavaScriptCore.vcproj", "JavaScriptCore", "JavaScriptCore.vcproj"), |
|
173 wcdir: os.path.join(wcdir, "WebCore.vcproj", "WebCore", "WebCore.vcproj") |
|
174 } |
|
175 |
|
176 for adir in files: |
|
177 project = MSVS8Project() |
|
178 project.loadFromXML(files[adir]) |
|
179 outputfile = os.path.join(adir, os.path.splitext(os.path.basename(files[adir]))[0] + "Sources.bkl") |
|
180 project.saveAsBkl(outputfile) |