Home | History | Annotate | Download | only in BuildSlaveSupport
      1 #!/usr/bin/python
      2 
      3 # Copyright (C) 2009 Apple 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 #
     15 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     16 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     19 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     20 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     21 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     22 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25 
     26 import optparse, os, shutil, subprocess, sys
     27 
     28 buildDirectory = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "WebKitBuild"))
     29 
     30 def main():
     31     parser = optparse.OptionParser("usage: %prog [options] [action]")
     32     parser.add_option("--platform", dest="platform")
     33     parser.add_option("--debug", action="store_const", const="debug", dest="configuration")
     34     parser.add_option("--release", action="store_const", const="release", dest="configuration")
     35 
     36     options, (action, ) = parser.parse_args()
     37     if not options.platform:
     38         parser.error("Platform is required")
     39     if not options.configuration:
     40         parser.error("Configuration is required")
     41     if action not in ('archive', 'extract'):
     42         parser.error("Action is required")
     43 
     44     if action == 'archive':
     45         archiveBuiltProduct(options.configuration, options.platform)
     46     else:
     47         extractBuiltProduct(options.configuration, options.platform)
     48 
     49 
     50 def archiveBuiltProduct(configuration, platform):
     51     assert platform in ('mac', 'win','qt')
     52 
     53     archiveFile = os.path.join(buildDirectory, configuration + ".zip")
     54 
     55     try:
     56         os.unlink(archiveFile)
     57     except OSError, e:
     58         if e.errno != 2:
     59             raise
     60 
     61     configurationBuildDirectory = os.path.join(buildDirectory, configuration.title())
     62 
     63     if platform == 'mac':
     64         return subprocess.call(["ditto", "-c", "-k", "--keepParent", "--sequesterRsrc", configurationBuildDirectory, archiveFile])
     65     elif platform == 'win':
     66         binDirectory = os.path.join(configurationBuildDirectory, "bin")
     67         thinDirectory = os.path.join(configurationBuildDirectory, "thin")
     68         thinBinDirectory = os.path.join(thinDirectory, "bin")
     69 
     70         if os.path.isdir(thinDirectory):
     71             shutil.rmtree(thinDirectory)
     72         os.mkdir(thinDirectory)
     73 
     74         if subprocess.call(["cp", "-R", binDirectory, thinBinDirectory]):
     75             return 1
     76 
     77         if subprocess.call("rm -f %s" % os.path.join(thinBinDirectory, "*.ilk"), shell=True):
     78             return 1
     79 
     80         if subprocess.call(["zip", "-r", archiveFile, "bin"], cwd=thinDirectory):
     81             return 1
     82 
     83         shutil.rmtree(thinDirectory)
     84 
     85     elif platform == 'qt':
     86         thinDirectory = os.path.join(configurationBuildDirectory, "thin")
     87 
     88         if os.path.isdir(thinDirectory):
     89             shutil.rmtree(thinDirectory)
     90         os.mkdir(thinDirectory)
     91 
     92         for dirname in ["bin", "lib", "JavaScriptCore"]:
     93             fromDir = os.path.join(configurationBuildDirectory, dirname, "*")
     94             toDir = os.path.join(thinDirectory, dirname)
     95             os.makedirs(toDir)
     96             if subprocess.call('cp -R %s %s' % (fromDir, toDir), shell=True):
     97                 return 1
     98 
     99         for root, dirs, files in os.walk(thinDirectory, topdown=False):
    100             for name in files:
    101                 if name.endswith(".o"):
    102                     os.remove(os.path.join(root, name))
    103 
    104         if subprocess.call(["zip", "-y", "-r", archiveFile, "."], cwd=thinDirectory):
    105             return 1
    106 
    107 def extractBuiltProduct(configuration, platform):
    108     assert platform in ('mac', 'win','qt')
    109 
    110     archiveFile = os.path.join(buildDirectory, configuration + ".zip")
    111     configurationBuildDirectory = os.path.join(buildDirectory, configuration.title())
    112 
    113     if platform == 'mac':
    114         if os.path.isdir(configurationBuildDirectory):
    115             shutil.rmtree(configurationBuildDirectory)
    116 
    117         if subprocess.call(["ditto", "-x", "-k", archiveFile, buildDirectory]):
    118             return 1
    119         os.unlink(archiveFile)
    120 
    121     elif platform == 'win':
    122         binDirectory = os.path.join(configurationBuildDirectory, "bin")        
    123         if os.path.isdir(binDirectory):
    124             shutil.rmtree(binDirectory)
    125 
    126         os.makedirs(binDirectory)
    127 
    128         safariPath = subprocess.Popen('cygpath -w "$PROGRAMFILES"/Safari',
    129                                       shell=True, stdout=subprocess.PIPE).communicate()[0].strip()
    130 
    131         if subprocess.call('cp -R "%s"/*.dll "%s"/*.resources %s' % (safariPath, safariPath, binDirectory), shell=True):
    132             return 1
    133 
    134         if subprocess.call(["unzip", "-o", archiveFile], cwd=configurationBuildDirectory):
    135             return 1
    136 
    137     elif platform == 'qt':
    138         if os.path.isdir(configurationBuildDirectory):
    139             shutil.rmtree(configurationBuildDirectory)
    140 
    141         if subprocess.call(["unzip", "-o", archiveFile, "-d", configurationBuildDirectory], cwd=buildDirectory):
    142             return 1
    143         os.unlink(archiveFile)
    144 
    145 if __name__ == '__main__':
    146     sys.exit(main())
    147