tizen beta release
[framework/web/webkit-efl.git] / Tools / BuildSlaveSupport / built-product-archive
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', 'gtk')
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' or platform == 'gtk':
86         thinDirectory = os.path.join(configurationBuildDirectory, "thin")
87
88         if os.path.isdir(thinDirectory):
89             shutil.rmtree(thinDirectory)
90         os.mkdir(thinDirectory)
91
92         if platform == 'qt':
93             neededDirectories = ["bin", "lib"]
94         elif platform == 'gtk':
95             neededDirectories = ["Programs", ".libs"]
96
97         for dirname in neededDirectories:
98             fromDir = os.path.join(configurationBuildDirectory, dirname, "*")
99             toDir = os.path.join(thinDirectory, dirname)
100             os.makedirs(toDir)
101             if subprocess.call('cp -R %s %s' % (fromDir, toDir), shell=True):
102                 return 1
103
104         for root, dirs, files in os.walk(thinDirectory, topdown=False):
105             for name in files:
106                 if name.endswith(".o"):
107                     os.remove(os.path.join(root, name))
108
109         if subprocess.call(["zip", "-y", "-r", archiveFile, "."], cwd=thinDirectory):
110             return 1
111
112 def extractBuiltProduct(configuration, platform):
113     assert platform in ('mac', 'win', 'qt', 'gtk')
114
115     archiveFile = os.path.join(buildDirectory, configuration + ".zip")
116     configurationBuildDirectory = os.path.join(buildDirectory, configuration.title())
117
118     if platform == 'mac':
119         if os.path.isdir(configurationBuildDirectory):
120             shutil.rmtree(configurationBuildDirectory)
121
122         if subprocess.call(["ditto", "-x", "-k", archiveFile, buildDirectory]):
123             return 1
124         os.unlink(archiveFile)
125
126     elif platform == 'win':
127         binDirectory = os.path.join(configurationBuildDirectory, "bin")        
128         if os.path.isdir(binDirectory):
129             shutil.rmtree(binDirectory)
130
131         os.makedirs(binDirectory)
132
133         safariPath = subprocess.Popen('cygpath -w "$PROGRAMFILES"/Safari',
134                                       shell=True, stdout=subprocess.PIPE).communicate()[0].strip()
135
136         if subprocess.call('cp -R "%s"/*.dll "%s"/*.resources %s' % (safariPath, safariPath, binDirectory), shell=True):
137             return 1
138
139         if subprocess.call(["unzip", "-o", archiveFile], cwd=configurationBuildDirectory):
140             return 1
141
142     elif platform == 'qt' or platform == 'gtk':
143         if os.path.isdir(configurationBuildDirectory):
144             shutil.rmtree(configurationBuildDirectory)
145
146         if subprocess.call(["unzip", "-o", archiveFile, "-d", configurationBuildDirectory], cwd=buildDirectory):
147             return 1
148         os.unlink(archiveFile)
149
150 if __name__ == '__main__':
151     sys.exit(main())