• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
26import optparse, os, shutil, subprocess, sys
27
28buildDirectory = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "WebKitBuild"))
29
30def 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
50def archiveBuiltProduct(configuration, platform):
51    assert platform in ('mac', 'win')
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    if platform == 'mac':
62        configurationBuildDirectory = os.path.join(buildDirectory, configuration.title())
63        return subprocess.call(["ditto", "-c", "-k", "--keepParent", "--sequesterRsrc", configurationBuildDirectory, archiveFile])
64    elif platform == 'win':
65        binDirectory = os.path.join(buildDirectory, "bin")
66        thinDirectory = os.path.join(buildDirectory, "thin")
67        thinBinDirectory = os.path.join(thinDirectory, "bin")
68
69        if os.path.isdir(thinDirectory):
70            shutil.rmtree(thinDirectory)
71        os.mkdir(thinDirectory)
72
73        if subprocess.call(["cp", "-R", binDirectory, thinBinDirectory]):
74            return 1
75
76        if subprocess.call("rm -f %s" % os.path.join(thinBinDirectory, "*.ilk"), shell=True):
77            return 1
78
79        if subprocess.call(["zip", "-r", archiveFile, "bin"], cwd=thinDirectory):
80            return 1
81
82        shutil.rmtree(thinDirectory)
83
84def extractBuiltProduct(configuration, platform):
85    assert platform in ('mac', 'win')
86
87    archiveFile = os.path.join(buildDirectory, configuration + ".zip")
88
89    if platform == 'mac':
90        configurationBuildDirectory = os.path.join(buildDirectory, configuration.title())
91
92        if os.path.isdir(configurationBuildDirectory):
93            shutil.rmtree(configurationBuildDirectory)
94
95        if subprocess.call(["ditto", "-x", "-k", archiveFile, buildDirectory]):
96            return 1
97        os.unlink(archiveFile)
98
99    elif platform == 'win':
100        binDirectory = os.path.join(buildDirectory, "bin")
101        if os.path.isdir(binDirectory):
102            shutil.rmtree(binDirectory)
103
104        os.mkdir(binDirectory)
105
106        safariPath = subprocess.Popen('cygpath -w "$PROGRAMFILES"/Safari',
107                                      shell=True, stdout=subprocess.PIPE).communicate()[0].strip()
108
109        if subprocess.call('cp -R "%s"/*.dll "%s"/*.resources %s' % (safariPath, safariPath, binDirectory), shell=True):
110            return 1
111
112        if subprocess.call(["unzip", "-o", archiveFile], cwd=buildDirectory):
113            return 1
114
115
116
117if __name__ == '__main__':
118    sys.exit(main())
119