1#!/usr/bin/env python 2 3# Copyright (C) 2009 Kevin Ollivier 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# 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. 13# 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. 25# 26# Script for building Mac .pkg installer 27 28import commands 29import distutils.sysconfig 30import glob 31import optparse 32import os 33import shutil 34import string 35import sys 36import tempfile 37 38script_dir = os.path.abspath(os.path.dirname(__file__)) 39sys.path.append(os.path.abspath(os.path.join(script_dir, "..", "build"))) 40 41from build_utils import * 42 43import wx 44 45wxwk_root = os.path.abspath(os.path.join(script_dir, "..", "..", "..")) 46wxwebkit_dir = os.path.abspath(os.path.join(wxwk_root, "WebKitBuild", get_config(wxwk_root) + git_branch_name())) 47 48wx_version = wx.__version__[:5] 49py_version = sys.version[:3] 50 51wxwk_version = svn_revision() 52 53platform = "osx" 54 55pkgname = "wxWebKit-%s-wx%s-py%s" % (platform, wx_version[:3], py_version) 56 57tempdir = "/tmp/%s" % (pkgname) 58 59if os.path.exists(tempdir): 60 shutil.rmtree(tempdir) 61 os.makedirs(tempdir) 62 63installroot = os.path.join(tempdir, "install-root") 64installapps = os.path.join(tempdir, "install-apps") 65 66sp_root = distutils.sysconfig.get_python_lib() 67wx_root = sp_root 68if 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) 71sitepackages = "%s/wx-%s-mac-unicode/wx" % (sp_root, wx_version[:3]) 72prefix = sitepackages 73 74def mac_update_dependencies(dylib, prefix): 75 """ 76 Copies any non-system dependencies into the bundle, and 77 updates the install name path to the new path in the bundle. 78 """ 79 global wx_root 80 system_prefixes = ["/usr/lib", "/System/Library", wx_root] 81 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 87 copy = True 88 for sys_prefix in system_prefixes: 89 if filename.startswith(sys_prefix): 90 copy = False 91 92 if copy: 93 copydir = os.path.dirname(dylib) 94 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)) 101 102 os.system("install_name_tool -change %s %s %s" % (filename, dest_filename, dylib)) 103 104def exitIfError(cmd): 105 print cmd 106 retval = os.system(cmd) 107 if retval != 0: 108 if os.path.exists(tempdir): 109 shutil.rmtree(tempdir) 110 sys.exit(1) 111 112wxroot = installroot + prefix 113wxpythonroot = installroot + sitepackages 114 115try: 116 if not os.path.exists(wxroot): 117 os.makedirs(wxroot) 118 119 if not os.path.exists(wxpythonroot): 120 os.makedirs(wxpythonroot) 121 122 for wildcard in ["*.py", "*.so", "*.dylib"]: 123 files = glob.glob(os.path.join(wxwebkit_dir, wildcard)) 124 for afile in files: 125 shutil.copy(afile, wxpythonroot) 126 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) 132 133 demodir = installroot + "/Applications/wxWebKit/Demos" 134 if not os.path.exists(demodir): 135 os.makedirs(demodir) 136 137 shutil.copy(os.path.join(wxwk_root, "WebKit", "wx", "bindings", "python", "samples", "simple.py"), demodir) 138 139 if os.path.exists(pkgname + ".pkg"): 140 shutil.rmtree(pkgname + ".pkg") 141 142 pkg_args = ['--title ' + pkgname, 143 '--out %s.pkg' % pkgname, 144 '--version ' + wxwk_version.strip(), 145 '--id org.wxwebkit.wxwebkit', 146 '--domain system', 147 '--root-volume-only', 148 '--root ' + installroot, 149 '--resources %s/mac/resources' % script_dir, 150 '--verbose' 151 ] 152 153 packagemaker = "/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker" 154 exitIfError(packagemaker + " %s" % (string.join(pkg_args, " "))) 155finally: 156 if os.path.exists(tempdir): 157 shutil.rmtree(tempdir) 158