3 # Copyright (C) 2009 Kevin Ollivier All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 # Script for building Mac .pkg installer
29 import distutils.sysconfig
38 script_dir = os.path.abspath(os.path.dirname(__file__))
39 sys.path.append(os.path.abspath(os.path.join(script_dir, "..", "build")))
41 from build_utils import *
45 wxwk_root = os.path.abspath(os.path.join(script_dir, "..", "..", ".."))
46 wxwebkit_dir = os.path.abspath(os.path.join(wxwk_root, "WebKitBuild", get_config(wxwk_root) + git_branch_name()))
48 wx_version = wx.__version__[:5]
49 py_version = sys.version[:3]
51 wxwk_version = svn_revision()
55 pkgname = "wxWebKit-%s-wx%s-py%s" % (platform, wx_version[:3], py_version)
57 tempdir = "/tmp/%s" % (pkgname)
59 if os.path.exists(tempdir):
60 shutil.rmtree(tempdir)
63 installroot = os.path.join(tempdir, "install-root")
64 installapps = os.path.join(tempdir, "install-apps")
66 sp_root = distutils.sysconfig.get_python_lib()
68 if sys.platform.startswith("darwin"):
69 wx_root = "/usr/local/lib/wxPython-unicode-%s" % wx.__version__
70 sp_root = "%s/lib/python%s/site-packages" % (wx_root, py_version)
71 sitepackages = "%s/wx-%s-mac-unicode/wx" % (sp_root, wx_version[:3])
74 def mac_update_dependencies(dylib, prefix):
76 Copies any non-system dependencies into the bundle, and
77 updates the install name path to the new path in the bundle.
80 system_prefixes = ["/usr/lib", "/System/Library", wx_root]
82 output = commands.getoutput("otool -L %s" % dylib).strip()
83 for line in output.split("\n"):
84 filename = line.split("(")[0].strip()
85 if os.path.exists(filename):
86 print "checking dll %s" % filename
88 for sys_prefix in system_prefixes:
89 if filename.startswith(sys_prefix):
93 copydir = os.path.dirname(dylib)
95 filedir, basename = os.path.split(filename)
96 dest_filename = os.path.join(prefix, basename)
97 copyname = os.path.join(copydir, basename)
98 if not os.path.exists(copyname):
99 shutil.copy(filename, copydir)
100 os.system("install_name_tool -id %s %s" % (dest_filename, copyname))
102 os.system("install_name_tool -change %s %s %s" % (filename, dest_filename, dylib))
104 def exitIfError(cmd):
106 retval = os.system(cmd)
108 if os.path.exists(tempdir):
109 shutil.rmtree(tempdir)
112 wxroot = installroot + prefix
113 wxpythonroot = installroot + sitepackages
116 if not os.path.exists(wxroot):
119 if not os.path.exists(wxpythonroot):
120 os.makedirs(wxpythonroot)
122 for wildcard in ["*.py", "*.so", "*.dylib"]:
123 files = glob.glob(os.path.join(wxwebkit_dir, wildcard))
125 shutil.copy(afile, wxpythonroot)
127 if sys.platform.startswith("darwin"):
128 dylib_path = os.path.join(wxpythonroot, "libwxwebkit.dylib")
129 os.system("install_name_tool -id %s %s" % (os.path.join(prefix, "libwxwebkit.dylib"), dylib_path))
130 mac_update_dependencies(dylib_path, prefix)
131 mac_update_dependencies(os.path.join(wxpythonroot, "_webview.so"), prefix)
133 demodir = installroot + "/Applications/wxWebKit/Demos"
134 if not os.path.exists(demodir):
137 shutil.copy(os.path.join(wxwk_root, "WebKit", "wx", "bindings", "python", "samples", "simple.py"), demodir)
139 if os.path.exists(pkgname + ".pkg"):
140 shutil.rmtree(pkgname + ".pkg")
142 pkg_args = ['--title ' + pkgname,
143 '--out %s.pkg' % pkgname,
144 '--version ' + wxwk_version.strip(),
145 '--id org.wxwebkit.wxwebkit',
147 '--root-volume-only',
148 '--root ' + installroot,
149 '--resources %s/mac/resources' % script_dir,
153 packagemaker = "/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker"
154 exitIfError(packagemaker + " %s" % (string.join(pkg_args, " ")))
156 if os.path.exists(tempdir):
157 shutil.rmtree(tempdir)