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
30 import distutils.sysconfig
39 script_dir = os.path.abspath(os.path.dirname(__file__))
40 sys.path.append(os.path.abspath(os.path.join(script_dir, "..", "build")))
42 from build_utils import *
46 wxwk_root = os.path.abspath(os.path.join(script_dir, "..", "..", ".."))
47 wxwebkit_dir = os.path.abspath(os.path.join(wxwk_root, "WebKitBuild", get_config(wxwk_root) + git_branch_name()))
49 wx_version = wx.__version__[:5]
50 py_version = sys.version[:3]
52 date = str(datetime.date.today())
56 pkgname = "wxWebKit-%s-wx%s-py%s-%s" % (platform, wx_version[:3], py_version, date)
58 tempdir = "/tmp/%s" % (pkgname)
60 if os.path.exists(tempdir):
61 shutil.rmtree(tempdir)
64 installroot = os.path.join(tempdir, "install-root")
65 installapps = os.path.join(tempdir, "install-apps")
67 sp_root = distutils.sysconfig.get_python_lib()
69 if sys.platform.startswith("darwin"):
70 wx_root = "/usr/local/lib/wxPython-unicode-%s" % wx.__version__
71 sp_root = "%s/lib/python%s/site-packages" % (wx_root, py_version)
72 sitepackages = "%s/wx-%s-mac-unicode/wx" % (sp_root, wx_version[:3])
75 def mac_update_dependencies(dylib, prefix):
77 Copies any non-system dependencies into the bundle, and
78 updates the install name path to the new path in the bundle.
81 system_prefixes = ["/usr/lib", "/System/Library", wx_root]
83 output = commands.getoutput("otool -L %s" % dylib).strip()
84 for line in output.split("\n"):
85 filename = line.split("(")[0].strip()
86 if os.path.exists(filename):
87 print "checking dll %s" % filename
89 for sys_prefix in system_prefixes:
90 if filename.startswith(sys_prefix):
94 copydir = os.path.dirname(dylib)
96 filedir, basename = os.path.split(filename)
97 dest_filename = os.path.join(prefix, basename)
98 copyname = os.path.join(copydir, basename)
99 if not os.path.exists(copyname):
100 shutil.copy(filename, copydir)
101 os.system("install_name_tool -id %s %s" % (dest_filename, copyname))
103 os.system("install_name_tool -change %s %s %s" % (filename, dest_filename, dylib))
105 def exitIfError(cmd):
107 retval = os.system(cmd)
109 if os.path.exists(tempdir):
110 shutil.rmtree(tempdir)
113 wxroot = installroot + prefix
114 wxpythonroot = installroot + sitepackages
117 if not os.path.exists(wxroot):
120 if not os.path.exists(wxpythonroot):
121 os.makedirs(wxpythonroot)
123 for wildcard in ["*.py", "*.so", "*.dylib"]:
124 files = glob.glob(os.path.join(wxwebkit_dir, wildcard))
126 shutil.copy(afile, wxpythonroot)
128 if sys.platform.startswith("darwin"):
129 dylib_path = os.path.join(wxpythonroot, "libwxwebkit.dylib")
130 os.system("install_name_tool -id %s %s" % (os.path.join(prefix, "libwxwebkit.dylib"), dylib_path))
131 mac_update_dependencies(dylib_path, prefix)
132 mac_update_dependencies(os.path.join(wxpythonroot, "_webview.so"), prefix)
134 demodir = installroot + "/Applications/wxWebKit/Demos"
135 if not os.path.exists(demodir):
138 shutil.copy(os.path.join(wxwk_root, "WebKit", "wx", "bindings", "python", "samples", "simple.py"), demodir)
140 if os.path.exists(pkgname + ".pkg"):
141 shutil.rmtree(pkgname + ".pkg")
143 pkg_args = ['--title ' + pkgname,
144 '--out %s.pkg' % pkgname,
145 '--version ' + date.strip(),
146 '--id org.wxwebkit.wxwebkit',
148 '--root-volume-only',
149 '--root ' + installroot,
150 '--resources %s/mac/resources' % script_dir,
154 packagemaker = "/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker"
155 exitIfError(packagemaker + " %s" % (string.join(pkg_args, " ")))
157 if os.path.exists(tempdir):
158 shutil.rmtree(tempdir)