3 # Copyright (C) 2009 Apple 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.
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.
26 import optparse, os, shutil, subprocess, sys
28 buildDirectory = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "WebKitBuild"))
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")
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")
44 if action == 'archive':
45 archiveBuiltProduct(options.configuration, options.platform)
47 extractBuiltProduct(options.configuration, options.platform)
50 def archiveBuiltProduct(configuration, platform):
51 assert platform in ('mac', 'win', 'qt', 'gtk')
53 archiveFile = os.path.join(buildDirectory, configuration + ".zip")
56 os.unlink(archiveFile)
61 configurationBuildDirectory = os.path.join(buildDirectory, configuration.title())
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")
70 if os.path.isdir(thinDirectory):
71 shutil.rmtree(thinDirectory)
72 os.mkdir(thinDirectory)
74 if subprocess.call(["cp", "-R", binDirectory, thinBinDirectory]):
77 if subprocess.call("rm -f %s" % os.path.join(thinBinDirectory, "*.ilk"), shell=True):
80 if subprocess.call(["zip", "-r", archiveFile, "bin"], cwd=thinDirectory):
83 shutil.rmtree(thinDirectory)
85 elif platform == 'qt' or platform == 'gtk':
86 thinDirectory = os.path.join(configurationBuildDirectory, "thin")
88 if os.path.isdir(thinDirectory):
89 shutil.rmtree(thinDirectory)
90 os.mkdir(thinDirectory)
93 neededDirectories = ["bin", "lib"]
94 elif platform == 'gtk':
95 neededDirectories = ["Programs", ".libs"]
97 for dirname in neededDirectories:
98 fromDir = os.path.join(configurationBuildDirectory, dirname, "*")
99 toDir = os.path.join(thinDirectory, dirname)
101 if subprocess.call('cp -R %s %s' % (fromDir, toDir), shell=True):
104 for root, dirs, files in os.walk(thinDirectory, topdown=False):
106 if name.endswith(".o"):
107 os.remove(os.path.join(root, name))
109 if subprocess.call(["zip", "-y", "-r", archiveFile, "."], cwd=thinDirectory):
112 def extractBuiltProduct(configuration, platform):
113 assert platform in ('mac', 'win', 'qt', 'gtk')
115 archiveFile = os.path.join(buildDirectory, configuration + ".zip")
116 configurationBuildDirectory = os.path.join(buildDirectory, configuration.title())
118 if platform == 'mac':
119 if os.path.isdir(configurationBuildDirectory):
120 shutil.rmtree(configurationBuildDirectory)
122 if subprocess.call(["ditto", "-x", "-k", archiveFile, buildDirectory]):
124 os.unlink(archiveFile)
126 elif platform == 'win':
127 binDirectory = os.path.join(configurationBuildDirectory, "bin")
128 if os.path.isdir(binDirectory):
129 shutil.rmtree(binDirectory)
131 os.makedirs(binDirectory)
133 safariPath = subprocess.Popen('cygpath -w "$PROGRAMFILES"/Safari',
134 shell=True, stdout=subprocess.PIPE).communicate()[0].strip()
136 if subprocess.call('cp -R "%s"/*.dll "%s"/*.resources %s' % (safariPath, safariPath, binDirectory), shell=True):
139 if subprocess.call(["unzip", "-o", archiveFile], cwd=configurationBuildDirectory):
142 elif platform == 'qt' or platform == 'gtk':
143 if os.path.isdir(configurationBuildDirectory):
144 shutil.rmtree(configurationBuildDirectory)
146 if subprocess.call(["unzip", "-o", archiveFile, "-d", configurationBuildDirectory], cwd=buildDirectory):
148 os.unlink(archiveFile)
150 if __name__ == '__main__':