Prerender first frame of new view size before angle is changed.
[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 # Copyright (C) 2012 Google Inc. All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # 1.  Redistributions of source code must retain the above copyright
11 #     notice, this list of conditions and the following disclaimer. 
12 # 2.  Redistributions in binary form must reproduce the above copyright
13 #     notice, this list of conditions and the following disclaimer in the
14 #     documentation and/or other materials provided with the distribution. 
15 #
16 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
17 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
20 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27 import optparse
28 import os
29 import shutil
30 import subprocess
31 import sys
32 import zipfile
33
34 _buildDirectory = None
35
36
37 def main():
38     parser = optparse.OptionParser("usage: %prog [options] [action]")
39     parser.add_option("--platform", dest="platform")
40     parser.add_option("--debug", action="store_const", const="debug", dest="configuration")
41     parser.add_option("--release", action="store_const", const="release", dest="configuration")
42
43     options, (action, ) = parser.parse_args()
44     if not options.platform:
45         parser.error("Platform is required")
46         return 1
47     if not options.configuration:
48         parser.error("Configuration is required")
49         return 1
50     if action not in ('archive', 'extract'):
51         parser.error("Action is required")
52         return 1
53
54     if not determineWebKitBuildDirectory(options.platform, options.configuration):
55         print >> sys.stderr, "Could not determine build directory"
56         return 1
57
58     if action == 'archive':
59         return archiveBuiltProduct(options.configuration, options.platform)
60     else:
61         return extractBuiltProduct(options.configuration, options.platform)
62
63
64 def determineWebKitBuildDirectory(platform, configuration):
65     global _buildDirectory
66     _buildDirectory = subprocess.Popen(['perl', os.path.join(os.path.dirname(__file__), "..", "Scripts", "webkit-build-directory"),
67         "--" + platform, "--" + configuration, '--top-level'], stdout=subprocess.PIPE).communicate()[0].strip()
68     return _buildDirectory
69
70
71 def removeDirectoryIfExists(thinDirectory):
72     if os.path.isdir(thinDirectory):
73         shutil.rmtree(thinDirectory)
74
75
76 def copyBuildFiles(source, destination, patterns):
77     shutil.copytree(source, destination, ignore=shutil.ignore_patterns(*patterns))
78
79
80 def createZipManually(directoryToZip, archiveFile):
81     archiveZip = zipfile.ZipFile(archiveFile, "w")
82
83     for path, dirNames, fileNames in os.walk(directoryToZip):
84         relativePath = os.path.relpath(path, directoryToZip)
85         for fileName in fileNames:
86             archiveZip.write(os.path.join(path, fileName), os.path.join(relativePath, fileName))
87
88     archiveZip.close()
89
90
91 def createZip(directoryToZip, configuration, archiveConfigurationOnMac=False):
92     archiveDir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "WebKitBuild"))
93
94     # Chromium bots may not have this directory
95     if not os.path.isdir(archiveDir):
96         os.mkdir(archiveDir)
97
98     archiveFile = os.path.join(archiveDir, configuration + ".zip")
99
100     try:
101         os.unlink(archiveFile)
102     except OSError, e:
103         if e.errno != 2:
104             raise
105
106     if sys.platform == 'darwin':
107         if archiveConfigurationOnMac:
108             return subprocess.call(["ditto", "-c", "-k", "--keepParent", "--sequesterRsrc", directoryToZip, archiveFile])
109         return subprocess.call(["ditto", "-c", "-k", "--sequesterRsrc", directoryToZip, archiveFile])
110     elif sys.platform == 'cygwin':
111         return subprocess.call(["zip", "-r", archiveFile, "bin"], cwd=directoryToZip)
112     elif sys.platform == 'win32':
113         createZipManually(directoryToZip, archiveFile)
114         return 0
115     elif sys.platform.startswith('linux'):
116         return subprocess.call(["zip", "-y", "-r", archiveFile, "."], cwd=directoryToZip)
117
118
119 def archiveBuiltProduct(configuration, platform):
120     assert platform in ('mac', 'win', 'qt', 'gtk', 'efl', 'chromium')
121
122     configurationBuildDirectory = os.path.join(_buildDirectory, configuration.title())
123
124     if platform == 'mac':
125         return createZip(configurationBuildDirectory, configuration, archiveConfigurationOnMac=True)
126     elif platform == 'win':
127         binDirectory = os.path.join(configurationBuildDirectory, "bin")
128         thinDirectory = os.path.join(configurationBuildDirectory, "thin")
129         thinBinDirectory = os.path.join(thinDirectory, "bin")
130
131         removeDirectoryIfExists(thinDirectory)
132         copyBuildFiles(binDirectory, thinBinDirectory, ['*.ilk'])
133         if createZip(thinDirectory, configuration):
134             return 1
135
136         shutil.rmtree(thinDirectory)
137
138     elif platform == 'qt' or platform == 'gtk' or platform == 'efl':
139         thinDirectory = os.path.join(configurationBuildDirectory, "thin")
140
141         removeDirectoryIfExists(thinDirectory)
142         os.mkdir(thinDirectory)
143
144         if platform == 'qt' or platform == 'efl':
145             neededDirectories = ["bin", "lib"]
146         elif platform == 'gtk':
147             neededDirectories = ["Programs", ".libs", "Libraries"]
148
149         for dirname in neededDirectories:
150             fromDir = os.path.join(configurationBuildDirectory, dirname, ".")
151             toDir = os.path.join(thinDirectory, dirname)
152             os.makedirs(toDir)
153             if subprocess.call('cp -R %s %s' % (fromDir, toDir), shell=True):
154                 return 1
155
156         for root, dirs, files in os.walk(thinDirectory, topdown=False):
157             for name in files:
158                 if name.endswith(".o"):
159                     os.remove(os.path.join(root, name))
160
161         if createZip(thinDirectory, configuration):
162             return 1
163
164     elif platform == 'chromium':
165         thinDirectory = os.path.join(configurationBuildDirectory, "thin")
166
167         removeDirectoryIfExists(thinDirectory)
168         copyBuildFiles(configurationBuildDirectory, thinDirectory,
169             ['.svn', '*.a', '*.d', '*.dSYM', '*.o', '*.ilk', '*.lib', '*.idb', 'BuildLog.htm', '*.obj',
170             '*.pdb', '*.pch', '*.tlog', '*.lastbuildstate'])
171         if createZip(thinDirectory, configuration):
172             return 1
173
174
175 def unzipArchive(directoryToExtractTo, configuration):
176     archiveDir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "WebKitBuild"))
177     assert os.path.isdir(archiveDir)
178     archiveFile = os.path.join(archiveDir, configuration + ".zip")
179
180     if sys.platform == 'darwin':
181         if subprocess.call(["ditto", "-x", "-k", archiveFile, directoryToExtractTo]):
182             return 1
183     elif sys.platform == 'cygwin' or sys.platform.startswith('linux'):
184         if subprocess.call(["unzip", "-o", archiveFile], cwd=directoryToExtractTo):
185             return 1
186     elif sys.platform == 'win32':
187         archive = zipfile.ZipFile(archiveFile, "r")
188         archive.extractall(directoryToExtractTo)
189         archive.close()
190
191     os.unlink(archiveFile)
192
193
194 def extractBuiltProduct(configuration, platform):
195     assert platform in ('mac', 'win', 'qt', 'gtk', 'efl', 'chromium')
196
197     archiveFile = os.path.join(_buildDirectory, configuration + ".zip")
198     configurationBuildDirectory = os.path.join(_buildDirectory, configuration.title())
199
200     removeDirectoryIfExists(configurationBuildDirectory)
201     os.makedirs(configurationBuildDirectory)
202
203     if platform == 'mac':
204         return unzipArchive(_buildDirectory, configuration)
205     elif platform == 'win':
206         binDirectory = os.path.join(configurationBuildDirectory, "bin")
207         os.makedirs(binDirectory)
208
209         safariPath = subprocess.Popen('cygpath -w "$PROGRAMFILES"/Safari',
210                                       shell=True, stdout=subprocess.PIPE).communicate()[0].strip()
211
212         if subprocess.call('cp -R "%s"/*.dll "%s"/*.resources %s' % (safariPath, safariPath, binDirectory), shell=True):
213             return 1
214
215         return unzipArchive(configurationBuildDirectory, configuration)
216     elif platform == 'qt' or platform == 'gtk' or platform == 'efl' or platform == 'chromium':
217         return unzipArchive(configurationBuildDirectory, configuration)
218
219
220 if __name__ == '__main__':
221     sys.exit(main())