3 # Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
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.
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.
29 # A script to make sure the source file list for the Bakefiles is up-to-date
30 # with the MSVC project files.
33 from xml.dom import minidom
40 self.precomp_headers = True
41 self.warning_level = "default"
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(";")
52 if tool.attributes.has_key("PreprocessorDefinitions"):
53 self.defines = tool.attributes["PreprocessorDefinitions"].value.split(";")
57 self.target_type="exe"
58 self.target_name="Release"
61 self.pre_build_step = ""
62 self.compiler = MSVS8Compiler()
64 def fromXML(self, config):
65 if config.attributes.has_key("Name"):
66 self.target_name = config.attributes["Name"].value
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"
76 print "Unknown project type %s. Exiting..." % (config_type)
79 tools = config.getElementsByTagName("Tool")
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
86 if tool.attributes.has_key("Name") and tool.attributes["Name"].value == "VCCLCompilerTool":
87 self.compiler.fromXML(tool)
90 target = doc.createElement(self.target_type)
91 target.setAttribute("id", self.target_name)
100 self.prefix = "WEBCORE_"
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()
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)
115 def asBkl(self, doc):
116 sources = doc.createElement("set")
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")
126 for afile in self.files:
127 sources_text += afile + "\n"
129 sources.appendChild(doc.createTextNode(sources_text))
136 self.prefix = "WEBCORE_"
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)
146 if filename.find("JavaScriptCore") != -1:
147 self.prefix = "JSCORE_"
149 files = doc.getElementsByTagName("Filter")
151 files = MSVS8Filter()
152 files.prefix = self.prefix
154 self.file_list.append(files)
156 def saveAsBkl(self, filename):
157 doc = minidom.Document()
158 makefile = doc.createElement("makefile")
160 for files in self.file_list:
161 makefile.appendChild(files.asBkl(doc))
163 doc.appendChild(makefile)
165 outfile = open(filename, "w")
166 outfile.write(doc.toprettyxml())
169 jsdir = os.path.join(WebKitRoot, "JavaScriptCore")
170 wcdir = os.path.join(WebKitRoot, "WebCore")
172 files = { jsdir: os.path.join(jsdir, "JavaScriptCore.vcproj", "JavaScriptCore", "JavaScriptCore.vcproj"),
173 wcdir: os.path.join(wcdir, "WebCore.vcproj", "WebCore", "WebCore.vcproj")
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)