|
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 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 |
|
84 elif platform == 'qt': |
|
85 configurationBuildDirectory = os.path.join(buildDirectory, configuration.title()) |
|
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 if subprocess.call(["cp", "-R", fromDir, toDir]): |
|
96 return 1 |
|
97 |
|
98 for root, dirs, files in os.walk(thinDirectory, topdown=False): |
|
99 for name in files: |
|
100 if name.endswith(".o"): |
|
101 os.remove(os.path.join(root, name)) |
|
102 |
|
103 if subprocess.call(["zip", "-y", "-r", archiveFile, "."], cwd=thinDirectory): |
|
104 return 1 |
|
105 |
|
106 def extractBuiltProduct(configuration, platform): |
|
107 assert platform in ('mac', 'win','qt') |
|
108 |
|
109 archiveFile = os.path.join(buildDirectory, configuration + ".zip") |
|
110 |
|
111 if platform == 'mac': |
|
112 configurationBuildDirectory = os.path.join(buildDirectory, configuration.title()) |
|
113 |
|
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(buildDirectory, "bin") |
|
123 if os.path.isdir(binDirectory): |
|
124 shutil.rmtree(binDirectory) |
|
125 |
|
126 os.mkdir(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=buildDirectory): |
|
135 return 1 |
|
136 |
|
137 elif platform == 'qt': |
|
138 configurationBuildDirectory = os.path.join(buildDirectory, configuration.title()) |
|
139 |
|
140 if os.path.isdir(configurationBuildDirectory): |
|
141 shutil.rmtree(configurationBuildDirectory) |
|
142 |
|
143 if subprocess.call(["unzip", "-o", archiveFile, "-d", configurationBuildDirectory], cwd=buildDirectory): |
|
144 return 1 |
|
145 os.unlink(archiveFile) |
|
146 |
|
147 if __name__ == '__main__': |
|
148 sys.exit(main()) |