Home | History | Annotate | Download | only in Scripts
      1 #!/usr/bin/env python
      2 
      3 # Copyright (C) 2007 Kevin Ollivier  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 # 1. Redistributions of source code must retain the above copyright
      9 #    notice, this list of conditions and the following disclaimer.
     10 # 2. Redistributions in binary form must reproduce the above copyright
     11 #    notice, this list of conditions and the following disclaimer in the
     12 #    documentation and/or other materials provided with the distribution.
     13 #
     14 # THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     15 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     17 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     18 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     19 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     20 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     21 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     22 # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     24 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25 #
     26 # Make sure any port-independent files added to the Bakefile are
     27 # added to GTK, QT, etc. so that file updates can happen in one place.
     28 
     29 import os, sys
     30 from xml.dom import minidom
     31 
     32 scriptDir = os.path.abspath(sys.path[0])
     33 wkroot = os.path.abspath(os.path.join(scriptDir, "../.."))
     34 
     35 def getWebCoreFilesDict():
     36     """
     37     This method parses the WebCoreSources.bkl file, which has a list of all sources not specific
     38     to any port, and returns the result as a dictionary with items of the form
     39     (groupName, groupFiles). 
     40     """
     41     sources = {}
     42     sources_prefix = "WEBCORE_"
     43     filepath = os.path.join(wkroot, "Source", "WebCore", "WebCoreSources.bkl")
     44     assert(os.path.exists(filepath))
     45     
     46     doc = minidom.parse(filepath)
     47     for sourceGroup in doc.getElementsByTagName("set"):
     48         groupName = ""
     49         if sourceGroup.attributes.has_key("var"):
     50             groupName = sourceGroup.attributes["var"].value
     51             groupName = groupName.replace(sources_prefix, "")
     52             
     53         sourcesList = []
     54         for node in sourceGroup.childNodes:
     55             if node.nodeType == node.TEXT_NODE:
     56                 sourcesText = node.nodeValue.strip()
     57                 sourcesList = sourcesText.split("\n")
     58                 
     59         assert(groupName != "")
     60         assert(sourcesList != [])
     61         
     62         sources[groupName] = sourcesList
     63         
     64     return sources
     65 
     66 def generateWebCoreSourcesGTKAndQT(sources):
     67     """
     68     Convert the dictionary obtained from getWebCoreFilesDict() into a Unix makefile syntax,
     69     which IIUC is suitable for both GTK and QT build systems. To take advantage of this,
     70     QT and GTK would have to include the file "WebCore/sources.inc" into their makefiles.
     71     """
     72     makefileString = ""
     73     
     74     for key in sources.keys():
     75         makefileString += key + "+="
     76         for source in sources[key]:
     77             makefileString += " \\\n\t\t" + source.strip()
     78             
     79         makefileString += "\n\n"
     80     
     81     makefileString += "BASE_SOURCES +="
     82     for key in sources.keys():
     83         makefileString += " \\\n\t\t" + key
     84     
     85     outfile = os.path.join(wkroot, "Source", "WebCore", "sources.inc")
     86     sourcefile = open(outfile, "w")
     87     sourcefile.write(makefileString)
     88     sourcefile.close()
     89     
     90 sources = getWebCoreFilesDict()
     91 generateWebCoreSourcesGTKAndQT(sources)
     92 
     93 # Coming soon - MSVC and hopefully XCode support!
     94