Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 2 | """ |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 3 | This script is used to build "official" universal installers on macOS. |
| 4 | |
| 5 | NEW for 3.7.0: |
| 6 | - support Intel 64-bit-only () and 32-bit-only installer builds |
Ned Deily | b9e7fe3 | 2018-03-29 08:47:27 -0400 | [diff] [blame] | 7 | - build and use internal Tcl/Tk 8.6 for 10.6+ builds |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 8 | - deprecate use of explicit SDK (--sdk-path=) since all but the oldest |
| 9 | versions of Xcode support implicit setting of an SDK via environment |
| 10 | variables (SDKROOT and friends, see the xcrun man page for more info). |
| 11 | The SDK stuff was primarily needed for building universal installers |
| 12 | for 10.4; so as of 3.7.0, building installers for 10.4 is no longer |
| 13 | supported with build-installer. |
| 14 | - use generic "gcc" as compiler (CC env var) rather than "gcc-4.2" |
| 15 | |
| 16 | TODO: |
| 17 | - support SDKROOT and DEVELOPER_DIR xcrun env variables |
| 18 | - test with 10.5 and 10.4 and determine support status |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 19 | |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 20 | Please ensure that this script keeps working with Python 2.5, to avoid |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 21 | bootstrap issues (/usr/bin/python is Python 2.5 on OSX 10.5). Doc builds |
| 22 | use current versions of Sphinx and require a reasonably current python3. |
| 23 | Sphinx and dependencies are installed into a venv using the python3's pip |
| 24 | so will fetch them from PyPI if necessary. Since python3 is now used for |
| 25 | Sphinx, build-installer.py should also be converted to use python3! |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 26 | |
Ned Deily | b9e7fe3 | 2018-03-29 08:47:27 -0400 | [diff] [blame] | 27 | For 3.7.0, when building for a 10.6 or higher deployment target, |
| 28 | build-installer builds and links with its own copy of Tcl/Tk 8.6. |
| 29 | Otherwise, it requires an installed third-party version of |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 30 | Tcl/Tk 8.4 (for OS X 10.4 and 10.5 deployment targets), Tcl/TK 8.5 |
| 31 | (for 10.6 or later), or Tcl/TK 8.6 (for 10.9 or later) |
| 32 | installed in /Library/Frameworks. When installed, |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 33 | the Python built by this script will attempt to dynamically link first to |
| 34 | Tcl and Tk frameworks in /Library/Frameworks if available otherwise fall |
| 35 | back to the ones in /System/Library/Framework. For the build, we recommend |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 36 | installing the most recent ActiveTcl 8.6. 8.5, or 8.4 version, depending |
| 37 | on the deployment target. The actual version linked to depends on the |
| 38 | path of /Library/Frameworks/{Tcl,Tk}.framework/Versions/Current. |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 39 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 40 | Usage: see USAGE variable in the script. |
| 41 | """ |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 42 | import platform, os, sys, getopt, textwrap, shutil, stat, time, pwd, grp |
| 43 | try: |
| 44 | import urllib2 as urllib_request |
| 45 | except ImportError: |
| 46 | import urllib.request as urllib_request |
| 47 | |
| 48 | STAT_0o755 = ( stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
| 49 | | stat.S_IRGRP | stat.S_IXGRP |
| 50 | | stat.S_IROTH | stat.S_IXOTH ) |
| 51 | |
| 52 | STAT_0o775 = ( stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
| 53 | | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP |
| 54 | | stat.S_IROTH | stat.S_IXOTH ) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 55 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 56 | INCLUDE_TIMESTAMP = 1 |
| 57 | VERBOSE = 1 |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 58 | |
| 59 | from plistlib import Plist |
| 60 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 61 | try: |
| 62 | from plistlib import writePlist |
| 63 | except ImportError: |
| 64 | # We're run using python2.3 |
| 65 | def writePlist(plist, path): |
| 66 | plist.write(path) |
| 67 | |
| 68 | def shellQuote(value): |
| 69 | """ |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 70 | Return the string value in a form that can safely be inserted into |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 71 | a shell command. |
| 72 | """ |
| 73 | return "'%s'"%(value.replace("'", "'\"'\"'")) |
| 74 | |
| 75 | def grepValue(fn, variable): |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 76 | """ |
| 77 | Return the unquoted value of a variable from a file.. |
| 78 | QUOTED_VALUE='quotes' -> str('quotes') |
| 79 | UNQUOTED_VALUE=noquotes -> str('noquotes') |
| 80 | """ |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 81 | variable = variable + '=' |
| 82 | for ln in open(fn, 'r'): |
| 83 | if ln.startswith(variable): |
| 84 | value = ln[len(variable):].strip() |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 85 | return value.strip("\"'") |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 86 | raise RuntimeError("Cannot find variable %s" % variable[:-1]) |
| 87 | |
| 88 | _cache_getVersion = None |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 89 | |
| 90 | def getVersion(): |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 91 | global _cache_getVersion |
| 92 | if _cache_getVersion is None: |
| 93 | _cache_getVersion = grepValue( |
| 94 | os.path.join(SRCDIR, 'configure'), 'PACKAGE_VERSION') |
| 95 | return _cache_getVersion |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 96 | |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 97 | def getVersionMajorMinor(): |
| 98 | return tuple([int(n) for n in getVersion().split('.', 2)]) |
| 99 | |
| 100 | _cache_getFullVersion = None |
| 101 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 102 | def getFullVersion(): |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 103 | global _cache_getFullVersion |
| 104 | if _cache_getFullVersion is not None: |
| 105 | return _cache_getFullVersion |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 106 | fn = os.path.join(SRCDIR, 'Include', 'patchlevel.h') |
| 107 | for ln in open(fn): |
| 108 | if 'PY_VERSION' in ln: |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 109 | _cache_getFullVersion = ln.split()[-1][1:-1] |
| 110 | return _cache_getFullVersion |
| 111 | raise RuntimeError("Cannot find full version??") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 112 | |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 113 | FW_PREFIX = ["Library", "Frameworks", "Python.framework"] |
| 114 | FW_VERSION_PREFIX = "--undefined--" # initialized in parseOptions |
Ned Deily | dde4f63 | 2016-09-12 09:39:23 -0400 | [diff] [blame] | 115 | FW_SSL_DIRECTORY = "--undefined--" # initialized in parseOptions |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 116 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 117 | # The directory we'll use to create the build (will be erased and recreated) |
| 118 | WORKDIR = "/tmp/_py" |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 119 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 120 | # The directory we'll use to store third-party sources. Set this to something |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 121 | # else if you don't want to re-fetch required libraries every time. |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 122 | DEPSRC = os.path.join(WORKDIR, 'third-party') |
| 123 | DEPSRC = os.path.expanduser('~/Universal/other-sources') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 124 | |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 125 | universal_opts_map = { '32-bit': ('i386', 'ppc',), |
| 126 | '64-bit': ('x86_64', 'ppc64',), |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 127 | 'intel': ('i386', 'x86_64'), |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 128 | 'intel-32': ('i386',), |
| 129 | 'intel-64': ('x86_64',), |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 130 | '3-way': ('ppc', 'i386', 'x86_64'), |
| 131 | 'all': ('i386', 'ppc', 'x86_64', 'ppc64',) } |
| 132 | default_target_map = { |
| 133 | '64-bit': '10.5', |
| 134 | '3-way': '10.5', |
| 135 | 'intel': '10.5', |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 136 | 'intel-32': '10.4', |
| 137 | 'intel-64': '10.5', |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 138 | 'all': '10.5', |
| 139 | } |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 140 | |
| 141 | UNIVERSALOPTS = tuple(universal_opts_map.keys()) |
| 142 | |
| 143 | UNIVERSALARCHS = '32-bit' |
| 144 | |
| 145 | ARCHLIST = universal_opts_map[UNIVERSALARCHS] |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 146 | |
Ezio Melotti | 42da663 | 2011-03-15 05:18:48 +0200 | [diff] [blame] | 147 | # Source directory (assume we're in Mac/BuildScript) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 148 | SRCDIR = os.path.dirname( |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 149 | os.path.dirname( |
| 150 | os.path.dirname( |
Thomas Wouters | 73e5a5b | 2006-06-08 15:35:45 +0000 | [diff] [blame] | 151 | os.path.abspath(__file__ |
| 152 | )))) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 153 | |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 154 | # $MACOSX_DEPLOYMENT_TARGET -> minimum OS X level |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 155 | DEPTARGET = '10.5' |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 156 | |
Ned Deily | 04cdfa1 | 2014-06-25 13:36:14 -0700 | [diff] [blame] | 157 | def getDeptargetTuple(): |
| 158 | return tuple([int(n) for n in DEPTARGET.split('.')[0:2]]) |
| 159 | |
| 160 | def getTargetCompilers(): |
| 161 | target_cc_map = { |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 162 | '10.4': ('gcc-4.0', 'g++-4.0'), |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 163 | '10.5': ('gcc', 'g++'), |
| 164 | '10.6': ('gcc', 'g++'), |
Ned Deily | 04cdfa1 | 2014-06-25 13:36:14 -0700 | [diff] [blame] | 165 | } |
Ned Deily | acd7163 | 2018-02-24 14:30:44 -0500 | [diff] [blame] | 166 | return target_cc_map.get(DEPTARGET, ('gcc', 'g++') ) |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 167 | |
Ned Deily | 04cdfa1 | 2014-06-25 13:36:14 -0700 | [diff] [blame] | 168 | CC, CXX = getTargetCompilers() |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 169 | |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 170 | PYTHON_3 = getVersionMajorMinor() >= (3, 0) |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 171 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 172 | USAGE = textwrap.dedent("""\ |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 173 | Usage: build_python [options] |
| 174 | |
| 175 | Options: |
| 176 | -? or -h: Show this message |
| 177 | -b DIR |
| 178 | --build-dir=DIR: Create build here (default: %(WORKDIR)r) |
| 179 | --third-party=DIR: Store third-party sources here (default: %(DEPSRC)r) |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 180 | --sdk-path=DIR: Location of the SDK (deprecated, use SDKROOT env variable) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 181 | --src-dir=DIR: Location of the Python sources (default: %(SRCDIR)r) |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 182 | --dep-target=10.n macOS deployment target (default: %(DEPTARGET)r) |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 183 | --universal-archs=x universal architectures (options: %(UNIVERSALOPTS)r, default: %(UNIVERSALARCHS)r) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 184 | """)% globals() |
| 185 | |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 186 | # Dict of object file names with shared library names to check after building. |
| 187 | # This is to ensure that we ended up dynamically linking with the shared |
| 188 | # library paths and versions we expected. For example: |
| 189 | # EXPECTED_SHARED_LIBS['_tkinter.so'] = [ |
| 190 | # '/Library/Frameworks/Tcl.framework/Versions/8.5/Tcl', |
| 191 | # '/Library/Frameworks/Tk.framework/Versions/8.5/Tk'] |
| 192 | EXPECTED_SHARED_LIBS = {} |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 193 | |
Ned Deily | 1ca2ffd | 2018-01-30 17:29:53 -0500 | [diff] [blame] | 194 | # Are we building and linking with our own copy of Tcl/TK? |
Ned Deily | b9e7fe3 | 2018-03-29 08:47:27 -0400 | [diff] [blame] | 195 | # For now, do so if deployment target is 10.6+. |
Ned Deily | 1ca2ffd | 2018-01-30 17:29:53 -0500 | [diff] [blame] | 196 | def internalTk(): |
Ned Deily | b9e7fe3 | 2018-03-29 08:47:27 -0400 | [diff] [blame] | 197 | return getDeptargetTuple() >= (10, 6) |
Ned Deily | 1ca2ffd | 2018-01-30 17:29:53 -0500 | [diff] [blame] | 198 | |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 199 | # List of names of third party software built with this installer. |
| 200 | # The names will be inserted into the rtf version of the License. |
| 201 | THIRD_PARTY_LIBS = [] |
| 202 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 203 | # Instructions for building libraries that are necessary for building a |
| 204 | # batteries included python. |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 205 | # [The recipes are defined here for convenience but instantiated later after |
| 206 | # command line options have been processed.] |
| 207 | def library_recipes(): |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 208 | result = [] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 209 | |
Ned Deily | 04cdfa1 | 2014-06-25 13:36:14 -0700 | [diff] [blame] | 210 | LT_10_5 = bool(getDeptargetTuple() < (10, 5)) |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 211 | |
Ned Deily | dde4f63 | 2016-09-12 09:39:23 -0400 | [diff] [blame] | 212 | # Since Apple removed the header files for the deprecated system |
| 213 | # OpenSSL as of the Xcode 7 release (for OS X 10.10+), we do not |
| 214 | # have much choice but to build our own copy here, too. |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 215 | |
Ned Deily | dde4f63 | 2016-09-12 09:39:23 -0400 | [diff] [blame] | 216 | result.extend([ |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 217 | dict( |
Ned Deily | b405752 | 2018-04-07 02:36:02 -0400 | [diff] [blame] | 218 | name="OpenSSL 1.1.0h", |
| 219 | url="https://www.openssl.org/source/openssl-1.1.0h.tar.gz", |
| 220 | checksum='5271477e4d93f4ea032b665ef095ff24', |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 221 | buildrecipe=build_universal_openssl, |
| 222 | configure=None, |
| 223 | install=None, |
| 224 | ), |
Ned Deily | dde4f63 | 2016-09-12 09:39:23 -0400 | [diff] [blame] | 225 | ]) |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 226 | |
Ned Deily | 1ca2ffd | 2018-01-30 17:29:53 -0500 | [diff] [blame] | 227 | if internalTk(): |
Ned Deily | 5b3582c | 2013-10-25 00:41:46 -0700 | [diff] [blame] | 228 | result.extend([ |
| 229 | dict( |
Ned Deily | 9189e95 | 2018-02-27 17:36:12 -0500 | [diff] [blame] | 230 | name="Tcl 8.6.8", |
| 231 | url="ftp://ftp.tcl.tk/pub/tcl//tcl8_6/tcl8.6.8-src.tar.gz", |
| 232 | checksum='81656d3367af032e0ae6157eff134f89', |
Ned Deily | 5b3582c | 2013-10-25 00:41:46 -0700 | [diff] [blame] | 233 | buildDir="unix", |
| 234 | configure_pre=[ |
| 235 | '--enable-shared', |
| 236 | '--enable-threads', |
| 237 | '--libdir=/Library/Frameworks/Python.framework/Versions/%s/lib'%(getVersion(),), |
| 238 | ], |
| 239 | useLDFlags=False, |
| 240 | install='make TCL_LIBRARY=%(TCL_LIBRARY)s && make install TCL_LIBRARY=%(TCL_LIBRARY)s DESTDIR=%(DESTDIR)s'%{ |
| 241 | "DESTDIR": shellQuote(os.path.join(WORKDIR, 'libraries')), |
Ned Deily | 1ca2ffd | 2018-01-30 17:29:53 -0500 | [diff] [blame] | 242 | "TCL_LIBRARY": shellQuote('/Library/Frameworks/Python.framework/Versions/%s/lib/tcl8.6'%(getVersion())), |
Ned Deily | 5b3582c | 2013-10-25 00:41:46 -0700 | [diff] [blame] | 243 | }, |
| 244 | ), |
| 245 | dict( |
Ned Deily | 9189e95 | 2018-02-27 17:36:12 -0500 | [diff] [blame] | 246 | name="Tk 8.6.8", |
| 247 | url="ftp://ftp.tcl.tk/pub/tcl//tcl8_6/tk8.6.8-src.tar.gz", |
| 248 | checksum='5e0faecba458ee1386078fb228d008ba', |
| 249 | patches=[ |
| 250 | "tk868_on_10_8_10_9.patch", |
| 251 | ], |
Ned Deily | 5b3582c | 2013-10-25 00:41:46 -0700 | [diff] [blame] | 252 | buildDir="unix", |
| 253 | configure_pre=[ |
| 254 | '--enable-aqua', |
| 255 | '--enable-shared', |
| 256 | '--enable-threads', |
| 257 | '--libdir=/Library/Frameworks/Python.framework/Versions/%s/lib'%(getVersion(),), |
| 258 | ], |
| 259 | useLDFlags=False, |
| 260 | install='make TCL_LIBRARY=%(TCL_LIBRARY)s TK_LIBRARY=%(TK_LIBRARY)s && make install TCL_LIBRARY=%(TCL_LIBRARY)s TK_LIBRARY=%(TK_LIBRARY)s DESTDIR=%(DESTDIR)s'%{ |
| 261 | "DESTDIR": shellQuote(os.path.join(WORKDIR, 'libraries')), |
Ned Deily | 1ca2ffd | 2018-01-30 17:29:53 -0500 | [diff] [blame] | 262 | "TCL_LIBRARY": shellQuote('/Library/Frameworks/Python.framework/Versions/%s/lib/tcl8.6'%(getVersion())), |
| 263 | "TK_LIBRARY": shellQuote('/Library/Frameworks/Python.framework/Versions/%s/lib/tk8.6'%(getVersion())), |
Ned Deily | 5b3582c | 2013-10-25 00:41:46 -0700 | [diff] [blame] | 264 | }, |
| 265 | ), |
| 266 | ]) |
| 267 | |
Ned Deily | ed73010 | 2014-11-14 18:55:05 -0800 | [diff] [blame] | 268 | if PYTHON_3: |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 269 | result.extend([ |
| 270 | dict( |
Ned Deily | e6f8a73 | 2017-12-04 22:55:20 -0500 | [diff] [blame] | 271 | name="XZ 5.2.3", |
| 272 | url="http://tukaani.org/xz/xz-5.2.3.tar.gz", |
| 273 | checksum='ef68674fb47a8b8e741b34e429d86e9d', |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 274 | configure_pre=[ |
| 275 | '--disable-dependency-tracking', |
| 276 | ] |
| 277 | ), |
| 278 | ]) |
| 279 | |
| 280 | result.extend([ |
| 281 | dict( |
| 282 | name="NCurses 5.9", |
| 283 | url="http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.9.tar.gz", |
| 284 | checksum='8cb9c412e5f2d96bc6f459aa8c6282a1', |
| 285 | configure_pre=[ |
| 286 | "--enable-widec", |
| 287 | "--without-cxx", |
| 288 | "--without-cxx-binding", |
| 289 | "--without-ada", |
| 290 | "--without-curses-h", |
| 291 | "--enable-shared", |
| 292 | "--with-shared", |
| 293 | "--without-debug", |
| 294 | "--without-normal", |
| 295 | "--without-tests", |
| 296 | "--without-manpages", |
| 297 | "--datadir=/usr/share", |
| 298 | "--sysconfdir=/etc", |
| 299 | "--sharedstatedir=/usr/com", |
| 300 | "--with-terminfo-dirs=/usr/share/terminfo", |
| 301 | "--with-default-terminfo-dir=/usr/share/terminfo", |
| 302 | "--libdir=/Library/Frameworks/Python.framework/Versions/%s/lib"%(getVersion(),), |
| 303 | ], |
| 304 | patchscripts=[ |
| 305 | ("ftp://invisible-island.net/ncurses//5.9/ncurses-5.9-20120616-patch.sh.bz2", |
| 306 | "f54bf02a349f96a7c4f0d00922f3a0d4"), |
| 307 | ], |
| 308 | useLDFlags=False, |
| 309 | install='make && make install DESTDIR=%s && cd %s/usr/local/lib && ln -fs ../../../Library/Frameworks/Python.framework/Versions/%s/lib/lib* .'%( |
| 310 | shellQuote(os.path.join(WORKDIR, 'libraries')), |
| 311 | shellQuote(os.path.join(WORKDIR, 'libraries')), |
| 312 | getVersion(), |
| 313 | ), |
| 314 | ), |
| 315 | dict( |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 316 | name="SQLite 3.22.0", |
| 317 | url="https://www.sqlite.org/2018/sqlite-autoconf-3220000.tar.gz", |
| 318 | checksum='96b5648d542e8afa6ab7ffb8db8ddc3d', |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 319 | extra_cflags=('-Os ' |
Ned Deily | b3b0767 | 2016-09-05 17:31:14 -0700 | [diff] [blame] | 320 | '-DSQLITE_ENABLE_FTS5 ' |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 321 | '-DSQLITE_ENABLE_FTS4 ' |
| 322 | '-DSQLITE_ENABLE_FTS3_PARENTHESIS ' |
Ned Deily | 9625bf5 | 2017-12-04 21:50:29 -0500 | [diff] [blame] | 323 | '-DSQLITE_ENABLE_JSON1 ' |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 324 | '-DSQLITE_ENABLE_RTREE ' |
| 325 | '-DSQLITE_TCL=0 ' |
| 326 | '%s' % ('','-DSQLITE_WITHOUT_ZONEMALLOC ')[LT_10_5]), |
| 327 | configure_pre=[ |
| 328 | '--enable-threadsafe', |
| 329 | '--enable-shared=no', |
| 330 | '--enable-static=yes', |
| 331 | '--disable-readline', |
| 332 | '--disable-dependency-tracking', |
| 333 | ] |
| 334 | ), |
| 335 | ]) |
| 336 | |
Ned Deily | 04cdfa1 | 2014-06-25 13:36:14 -0700 | [diff] [blame] | 337 | if getDeptargetTuple() < (10, 5): |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 338 | result.extend([ |
| 339 | dict( |
Ned Deily | 4f7ff78 | 2011-01-15 05:29:12 +0000 | [diff] [blame] | 340 | name="Bzip2 1.0.6", |
| 341 | url="http://bzip.org/1.0.6/bzip2-1.0.6.tar.gz", |
| 342 | checksum='00b516f4704d4a7cb50a1d97e6e8e15b', |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 343 | configure=None, |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 344 | install='make install CC=%s CXX=%s, PREFIX=%s/usr/local/ CFLAGS="-arch %s"'%( |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 345 | CC, CXX, |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 346 | shellQuote(os.path.join(WORKDIR, 'libraries')), |
| 347 | ' -arch '.join(ARCHLIST), |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 348 | ), |
| 349 | ), |
| 350 | dict( |
| 351 | name="ZLib 1.2.3", |
| 352 | url="http://www.gzip.org/zlib/zlib-1.2.3.tar.gz", |
| 353 | checksum='debc62758716a169df9f62e6ab2bc634', |
| 354 | configure=None, |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 355 | install='make install CC=%s CXX=%s, prefix=%s/usr/local/ CFLAGS="-arch %s"'%( |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 356 | CC, CXX, |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 357 | shellQuote(os.path.join(WORKDIR, 'libraries')), |
| 358 | ' -arch '.join(ARCHLIST), |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 359 | ), |
| 360 | ), |
| 361 | dict( |
| 362 | # Note that GNU readline is GPL'd software |
Ned Deily | 4f7ff78 | 2011-01-15 05:29:12 +0000 | [diff] [blame] | 363 | name="GNU Readline 6.1.2", |
| 364 | url="http://ftp.gnu.org/pub/gnu/readline/readline-6.1.tar.gz" , |
| 365 | checksum='fc2f7e714fe792db1ce6ddc4c9fb4ef3', |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 366 | patchlevel='0', |
| 367 | patches=[ |
| 368 | # The readline maintainers don't do actual micro releases, but |
| 369 | # just ship a set of patches. |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 370 | ('http://ftp.gnu.org/pub/gnu/readline/readline-6.1-patches/readline61-001', |
| 371 | 'c642f2e84d820884b0bf9fd176bc6c3f'), |
| 372 | ('http://ftp.gnu.org/pub/gnu/readline/readline-6.1-patches/readline61-002', |
| 373 | '1a76781a1ea734e831588285db7ec9b1'), |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 374 | ] |
| 375 | ), |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 376 | ]) |
| 377 | |
Ned Deily | 4f7ff78 | 2011-01-15 05:29:12 +0000 | [diff] [blame] | 378 | if not PYTHON_3: |
| 379 | result.extend([ |
| 380 | dict( |
| 381 | name="Sleepycat DB 4.7.25", |
| 382 | url="http://download.oracle.com/berkeley-db/db-4.7.25.tar.gz", |
| 383 | checksum='ec2b87e833779681a0c3a814aa71359e', |
| 384 | buildDir="build_unix", |
| 385 | configure="../dist/configure", |
| 386 | configure_pre=[ |
| 387 | '--includedir=/usr/local/include/db4', |
| 388 | ] |
| 389 | ), |
| 390 | ]) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 391 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 392 | return result |
| 393 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 394 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 395 | # Instructions for building packages inside the .mpkg. |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 396 | def pkg_recipes(): |
| 397 | unselected_for_python3 = ('selected', 'unselected')[PYTHON_3] |
| 398 | result = [ |
| 399 | dict( |
| 400 | name="PythonFramework", |
| 401 | long_name="Python Framework", |
| 402 | source="/Library/Frameworks/Python.framework", |
| 403 | readme="""\ |
| 404 | This package installs Python.framework, that is the python |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 405 | interpreter and the standard library. |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 406 | """, |
| 407 | postflight="scripts/postflight.framework", |
| 408 | selected='selected', |
| 409 | ), |
| 410 | dict( |
| 411 | name="PythonApplications", |
| 412 | long_name="GUI Applications", |
| 413 | source="/Applications/Python %(VER)s", |
| 414 | readme="""\ |
| 415 | This package installs IDLE (an interactive Python IDE), |
| 416 | Python Launcher and Build Applet (create application bundles |
| 417 | from python scripts). |
Thomas Wouters | 73e5a5b | 2006-06-08 15:35:45 +0000 | [diff] [blame] | 418 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 419 | It also installs a number of examples and demos. |
| 420 | """, |
| 421 | required=False, |
| 422 | selected='selected', |
| 423 | ), |
| 424 | dict( |
| 425 | name="PythonUnixTools", |
| 426 | long_name="UNIX command-line tools", |
| 427 | source="/usr/local/bin", |
| 428 | readme="""\ |
| 429 | This package installs the unix tools in /usr/local/bin for |
| 430 | compatibility with older releases of Python. This package |
| 431 | is not necessary to use Python. |
| 432 | """, |
| 433 | required=False, |
| 434 | selected='selected', |
| 435 | ), |
| 436 | dict( |
| 437 | name="PythonDocumentation", |
| 438 | long_name="Python Documentation", |
| 439 | topdir="/Library/Frameworks/Python.framework/Versions/%(VER)s/Resources/English.lproj/Documentation", |
| 440 | source="/pydocs", |
| 441 | readme="""\ |
| 442 | This package installs the python documentation at a location |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 443 | that is useable for pydoc and IDLE. |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 444 | """, |
| 445 | postflight="scripts/postflight.documentation", |
| 446 | required=False, |
| 447 | selected='selected', |
| 448 | ), |
| 449 | dict( |
| 450 | name="PythonProfileChanges", |
| 451 | long_name="Shell profile updater", |
| 452 | readme="""\ |
| 453 | This packages updates your shell profile to make sure that |
| 454 | the Python tools are found by your shell in preference of |
| 455 | the system provided Python tools. |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 456 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 457 | If you don't install this package you'll have to add |
| 458 | "/Library/Frameworks/Python.framework/Versions/%(VER)s/bin" |
| 459 | to your PATH by hand. |
| 460 | """, |
| 461 | postflight="scripts/postflight.patch-profile", |
| 462 | topdir="/Library/Frameworks/Python.framework", |
| 463 | source="/empty-dir", |
| 464 | required=False, |
Ned Deily | ed73010 | 2014-11-14 18:55:05 -0800 | [diff] [blame] | 465 | selected='selected', |
| 466 | ), |
| 467 | dict( |
| 468 | name="PythonInstallPip", |
| 469 | long_name="Install or upgrade pip", |
| 470 | readme="""\ |
| 471 | This package installs (or upgrades from an earlier version) |
| 472 | pip, a tool for installing and managing Python packages. |
| 473 | """, |
| 474 | postflight="scripts/postflight.ensurepip", |
| 475 | topdir="/Library/Frameworks/Python.framework", |
| 476 | source="/empty-dir", |
| 477 | required=False, |
| 478 | selected='selected', |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 479 | ), |
| 480 | ] |
| 481 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 482 | return result |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 483 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 484 | def fatal(msg): |
| 485 | """ |
| 486 | A fatal error, bail out. |
| 487 | """ |
| 488 | sys.stderr.write('FATAL: ') |
| 489 | sys.stderr.write(msg) |
| 490 | sys.stderr.write('\n') |
| 491 | sys.exit(1) |
| 492 | |
| 493 | def fileContents(fn): |
| 494 | """ |
| 495 | Return the contents of the named file |
| 496 | """ |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 497 | return open(fn, 'r').read() |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 498 | |
| 499 | def runCommand(commandline): |
| 500 | """ |
Ezio Melotti | 1392500 | 2011-03-16 11:05:33 +0200 | [diff] [blame] | 501 | Run a command and raise RuntimeError if it fails. Output is suppressed |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 502 | unless the command fails. |
| 503 | """ |
| 504 | fd = os.popen(commandline, 'r') |
| 505 | data = fd.read() |
| 506 | xit = fd.close() |
Benjamin Peterson | 2a691a8 | 2008-03-31 01:51:45 +0000 | [diff] [blame] | 507 | if xit is not None: |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 508 | sys.stdout.write(data) |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 509 | raise RuntimeError("command failed: %s"%(commandline,)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 510 | |
| 511 | if VERBOSE: |
| 512 | sys.stdout.write(data); sys.stdout.flush() |
| 513 | |
| 514 | def captureCommand(commandline): |
| 515 | fd = os.popen(commandline, 'r') |
| 516 | data = fd.read() |
| 517 | xit = fd.close() |
Benjamin Peterson | 2a691a8 | 2008-03-31 01:51:45 +0000 | [diff] [blame] | 518 | if xit is not None: |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 519 | sys.stdout.write(data) |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 520 | raise RuntimeError("command failed: %s"%(commandline,)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 521 | |
| 522 | return data |
| 523 | |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 524 | def getTclTkVersion(configfile, versionline): |
| 525 | """ |
| 526 | search Tcl or Tk configuration file for version line |
| 527 | """ |
| 528 | try: |
| 529 | f = open(configfile, "r") |
Serhiy Storchaka | ba9ac5b | 2015-05-20 10:33:40 +0300 | [diff] [blame] | 530 | except OSError: |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 531 | fatal("Framework configuration file not found: %s" % configfile) |
| 532 | |
| 533 | for l in f: |
| 534 | if l.startswith(versionline): |
| 535 | f.close() |
| 536 | return l |
| 537 | |
| 538 | fatal("Version variable %s not found in framework configuration file: %s" |
| 539 | % (versionline, configfile)) |
| 540 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 541 | def checkEnvironment(): |
| 542 | """ |
| 543 | Check that we're running on a supported system. |
| 544 | """ |
| 545 | |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 546 | if sys.version_info[0:2] < (2, 5): |
| 547 | fatal("This script must be run with Python 2.5 (or later)") |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 548 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 549 | if platform.system() != 'Darwin': |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 550 | fatal("This script should be run on a macOS 10.5 (or later) system") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 551 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 552 | if int(platform.release().split('.')[0]) < 8: |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 553 | fatal("This script should be run on a macOS 10.5 (or later) system") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 554 | |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 555 | # Because we only support dynamic load of only one major/minor version of |
Ned Deily | 1ca2ffd | 2018-01-30 17:29:53 -0500 | [diff] [blame] | 556 | # Tcl/Tk, if we are not using building and using our own private copy of |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 557 | # Tcl/Tk, ensure: |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 558 | # 1. there is a user-installed framework (usually ActiveTcl) in (or linked |
| 559 | # in) SDKROOT/Library/Frameworks. As of Python 3.7.0, we no longer |
| 560 | # enforce that the version of the user-installed framework also |
| 561 | # exists in the system-supplied Tcl/Tk frameworks. Time to support |
| 562 | # Tcl/Tk 8.6 even if Apple does not. |
Ned Deily | 1ca2ffd | 2018-01-30 17:29:53 -0500 | [diff] [blame] | 563 | if not internalTk(): |
| 564 | frameworks = {} |
| 565 | for framework in ['Tcl', 'Tk']: |
| 566 | fwpth = 'Library/Frameworks/%s.framework/Versions/Current' % framework |
| 567 | libfw = os.path.join('/', fwpth) |
| 568 | usrfw = os.path.join(os.getenv('HOME'), fwpth) |
| 569 | frameworks[framework] = os.readlink(libfw) |
| 570 | if not os.path.exists(libfw): |
| 571 | fatal("Please install a link to a current %s %s as %s so " |
| 572 | "the user can override the system framework." |
| 573 | % (framework, frameworks[framework], libfw)) |
| 574 | if os.path.exists(usrfw): |
| 575 | fatal("Please rename %s to avoid possible dynamic load issues." |
| 576 | % usrfw) |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 577 | |
Ned Deily | 1ca2ffd | 2018-01-30 17:29:53 -0500 | [diff] [blame] | 578 | if frameworks['Tcl'] != frameworks['Tk']: |
| 579 | fatal("The Tcl and Tk frameworks are not the same version.") |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 580 | |
Ned Deily | 1ca2ffd | 2018-01-30 17:29:53 -0500 | [diff] [blame] | 581 | print(" -- Building with external Tcl/Tk %s frameworks" |
| 582 | % frameworks['Tk']) |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 583 | |
Ned Deily | 1ca2ffd | 2018-01-30 17:29:53 -0500 | [diff] [blame] | 584 | # add files to check after build |
| 585 | EXPECTED_SHARED_LIBS['_tkinter.so'] = [ |
| 586 | "/Library/Frameworks/Tcl.framework/Versions/%s/Tcl" |
| 587 | % frameworks['Tcl'], |
| 588 | "/Library/Frameworks/Tk.framework/Versions/%s/Tk" |
| 589 | % frameworks['Tk'], |
| 590 | ] |
| 591 | else: |
| 592 | print(" -- Building private copy of Tcl/Tk") |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 593 | print("") |
| 594 | |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 595 | # Remove inherited environment variables which might influence build |
| 596 | environ_var_prefixes = ['CPATH', 'C_INCLUDE_', 'DYLD_', 'LANG', 'LC_', |
| 597 | 'LD_', 'LIBRARY_', 'PATH', 'PYTHON'] |
| 598 | for ev in list(os.environ): |
| 599 | for prefix in environ_var_prefixes: |
| 600 | if ev.startswith(prefix) : |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 601 | print("INFO: deleting environment variable %s=%s" % ( |
| 602 | ev, os.environ[ev])) |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 603 | del os.environ[ev] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 604 | |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 605 | base_path = '/bin:/sbin:/usr/bin:/usr/sbin' |
| 606 | if 'SDK_TOOLS_BIN' in os.environ: |
| 607 | base_path = os.environ['SDK_TOOLS_BIN'] + ':' + base_path |
| 608 | # Xcode 2.5 on OS X 10.4 does not include SetFile in its usr/bin; |
| 609 | # add its fixed location here if it exists |
| 610 | OLD_DEVELOPER_TOOLS = '/Developer/Tools' |
| 611 | if os.path.isdir(OLD_DEVELOPER_TOOLS): |
| 612 | base_path = base_path + ':' + OLD_DEVELOPER_TOOLS |
| 613 | os.environ['PATH'] = base_path |
| 614 | print("Setting default PATH: %s"%(os.environ['PATH'])) |
Ned Deily | b364d9f | 2017-07-24 04:58:43 -0400 | [diff] [blame] | 615 | # Ensure we have access to sphinx-build. |
| 616 | # You may have to create a link in /usr/bin for it. |
Ned Deily | 1ff32a9 | 2014-09-05 15:57:05 -0700 | [diff] [blame] | 617 | runCommand('sphinx-build --version') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 618 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 619 | def parseOptions(args=None): |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 620 | """ |
| 621 | Parse arguments and update global settings. |
| 622 | """ |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 623 | global WORKDIR, DEPSRC, SRCDIR, DEPTARGET |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 624 | global UNIVERSALOPTS, UNIVERSALARCHS, ARCHLIST, CC, CXX |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 625 | global FW_VERSION_PREFIX |
Ned Deily | dde4f63 | 2016-09-12 09:39:23 -0400 | [diff] [blame] | 626 | global FW_SSL_DIRECTORY |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 627 | |
| 628 | if args is None: |
| 629 | args = sys.argv[1:] |
| 630 | |
| 631 | try: |
| 632 | options, args = getopt.getopt(args, '?hb', |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 633 | [ 'build-dir=', 'third-party=', 'sdk-path=' , 'src-dir=', |
| 634 | 'dep-target=', 'universal-archs=', 'help' ]) |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 635 | except getopt.GetoptError: |
| 636 | print(sys.exc_info()[1]) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 637 | sys.exit(1) |
| 638 | |
| 639 | if args: |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 640 | print("Additional arguments") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 641 | sys.exit(1) |
| 642 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 643 | deptarget = None |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 644 | for k, v in options: |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 645 | if k in ('-h', '-?', '--help'): |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 646 | print(USAGE) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 647 | sys.exit(0) |
| 648 | |
| 649 | elif k in ('-d', '--build-dir'): |
| 650 | WORKDIR=v |
| 651 | |
| 652 | elif k in ('--third-party',): |
| 653 | DEPSRC=v |
| 654 | |
| 655 | elif k in ('--sdk-path',): |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 656 | print(" WARNING: --sdk-path is no longer supported") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 657 | |
| 658 | elif k in ('--src-dir',): |
| 659 | SRCDIR=v |
| 660 | |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 661 | elif k in ('--dep-target', ): |
| 662 | DEPTARGET=v |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 663 | deptarget=v |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 664 | |
| 665 | elif k in ('--universal-archs', ): |
| 666 | if v in UNIVERSALOPTS: |
| 667 | UNIVERSALARCHS = v |
| 668 | ARCHLIST = universal_opts_map[UNIVERSALARCHS] |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 669 | if deptarget is None: |
| 670 | # Select alternate default deployment |
| 671 | # target |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 672 | DEPTARGET = default_target_map.get(v, '10.5') |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 673 | else: |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 674 | raise NotImplementedError(v) |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 675 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 676 | else: |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 677 | raise NotImplementedError(k) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 678 | |
| 679 | SRCDIR=os.path.abspath(SRCDIR) |
| 680 | WORKDIR=os.path.abspath(WORKDIR) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 681 | DEPSRC=os.path.abspath(DEPSRC) |
| 682 | |
Ned Deily | 04cdfa1 | 2014-06-25 13:36:14 -0700 | [diff] [blame] | 683 | CC, CXX = getTargetCompilers() |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 684 | |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 685 | FW_VERSION_PREFIX = FW_PREFIX[:] + ["Versions", getVersion()] |
Ned Deily | dde4f63 | 2016-09-12 09:39:23 -0400 | [diff] [blame] | 686 | FW_SSL_DIRECTORY = FW_VERSION_PREFIX[:] + ["etc", "openssl"] |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 687 | |
| 688 | print("-- Settings:") |
| 689 | print(" * Source directory: %s" % SRCDIR) |
| 690 | print(" * Build directory: %s" % WORKDIR) |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 691 | print(" * Third-party source: %s" % DEPSRC) |
| 692 | print(" * Deployment target: %s" % DEPTARGET) |
| 693 | print(" * Universal archs: %s" % str(ARCHLIST)) |
| 694 | print(" * C compiler: %s" % CC) |
| 695 | print(" * C++ compiler: %s" % CXX) |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 696 | print("") |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 697 | print(" -- Building a Python %s framework at patch level %s" |
| 698 | % (getVersion(), getFullVersion())) |
| 699 | print("") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 700 | |
| 701 | def extractArchive(builddir, archiveName): |
| 702 | """ |
| 703 | Extract a source archive into 'builddir'. Returns the path of the |
| 704 | extracted archive. |
| 705 | |
| 706 | XXX: This function assumes that archives contain a toplevel directory |
| 707 | that is has the same name as the basename of the archive. This is |
Ned Deily | 5b3582c | 2013-10-25 00:41:46 -0700 | [diff] [blame] | 708 | safe enough for almost anything we use. Unfortunately, it does not |
| 709 | work for current Tcl and Tk source releases where the basename of |
| 710 | the archive ends with "-src" but the uncompressed directory does not. |
| 711 | For now, just special case Tcl and Tk tar.gz downloads. |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 712 | """ |
| 713 | curdir = os.getcwd() |
| 714 | try: |
| 715 | os.chdir(builddir) |
| 716 | if archiveName.endswith('.tar.gz'): |
| 717 | retval = os.path.basename(archiveName[:-7]) |
Ned Deily | 5b3582c | 2013-10-25 00:41:46 -0700 | [diff] [blame] | 718 | if ((retval.startswith('tcl') or retval.startswith('tk')) |
| 719 | and retval.endswith('-src')): |
| 720 | retval = retval[:-4] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 721 | if os.path.exists(retval): |
| 722 | shutil.rmtree(retval) |
| 723 | fp = os.popen("tar zxf %s 2>&1"%(shellQuote(archiveName),), 'r') |
| 724 | |
| 725 | elif archiveName.endswith('.tar.bz2'): |
| 726 | retval = os.path.basename(archiveName[:-8]) |
| 727 | if os.path.exists(retval): |
| 728 | shutil.rmtree(retval) |
| 729 | fp = os.popen("tar jxf %s 2>&1"%(shellQuote(archiveName),), 'r') |
| 730 | |
| 731 | elif archiveName.endswith('.tar'): |
| 732 | retval = os.path.basename(archiveName[:-4]) |
| 733 | if os.path.exists(retval): |
| 734 | shutil.rmtree(retval) |
| 735 | fp = os.popen("tar xf %s 2>&1"%(shellQuote(archiveName),), 'r') |
| 736 | |
| 737 | elif archiveName.endswith('.zip'): |
| 738 | retval = os.path.basename(archiveName[:-4]) |
| 739 | if os.path.exists(retval): |
| 740 | shutil.rmtree(retval) |
| 741 | fp = os.popen("unzip %s 2>&1"%(shellQuote(archiveName),), 'r') |
| 742 | |
| 743 | data = fp.read() |
| 744 | xit = fp.close() |
| 745 | if xit is not None: |
| 746 | sys.stdout.write(data) |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 747 | raise RuntimeError("Cannot extract %s"%(archiveName,)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 748 | |
| 749 | return os.path.join(builddir, retval) |
| 750 | |
| 751 | finally: |
| 752 | os.chdir(curdir) |
| 753 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 754 | def downloadURL(url, fname): |
| 755 | """ |
| 756 | Download the contents of the url into the file. |
| 757 | """ |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 758 | fpIn = urllib_request.urlopen(url) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 759 | fpOut = open(fname, 'wb') |
| 760 | block = fpIn.read(10240) |
| 761 | try: |
| 762 | while block: |
| 763 | fpOut.write(block) |
| 764 | block = fpIn.read(10240) |
| 765 | fpIn.close() |
| 766 | fpOut.close() |
| 767 | except: |
| 768 | try: |
| 769 | os.unlink(fname) |
Serhiy Storchaka | ba9ac5b | 2015-05-20 10:33:40 +0300 | [diff] [blame] | 770 | except OSError: |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 771 | pass |
| 772 | |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 773 | def verifyThirdPartyFile(url, checksum, fname): |
| 774 | """ |
| 775 | Download file from url to filename fname if it does not already exist. |
| 776 | Abort if file contents does not match supplied md5 checksum. |
| 777 | """ |
| 778 | name = os.path.basename(fname) |
| 779 | if os.path.exists(fname): |
| 780 | print("Using local copy of %s"%(name,)) |
| 781 | else: |
| 782 | print("Did not find local copy of %s"%(name,)) |
| 783 | print("Downloading %s"%(name,)) |
| 784 | downloadURL(url, fname) |
| 785 | print("Archive for %s stored as %s"%(name, fname)) |
| 786 | if os.system( |
| 787 | 'MD5=$(openssl md5 %s) ; test "${MD5##*= }" = "%s"' |
| 788 | % (shellQuote(fname), checksum) ): |
| 789 | fatal('MD5 checksum mismatch for file %s' % fname) |
| 790 | |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 791 | def build_universal_openssl(basedir, archList): |
| 792 | """ |
| 793 | Special case build recipe for universal build of openssl. |
| 794 | |
| 795 | The upstream OpenSSL build system does not directly support |
| 796 | OS X universal builds. We need to build each architecture |
| 797 | separately then lipo them together into fat libraries. |
| 798 | """ |
| 799 | |
| 800 | # OpenSSL fails to build with Xcode 2.5 (on OS X 10.4). |
| 801 | # If we are building on a 10.4.x or earlier system, |
| 802 | # unilaterally disable assembly code building to avoid the problem. |
| 803 | no_asm = int(platform.release().split(".")[0]) < 9 |
| 804 | |
| 805 | def build_openssl_arch(archbase, arch): |
| 806 | "Build one architecture of openssl" |
| 807 | arch_opts = { |
| 808 | "i386": ["darwin-i386-cc"], |
| 809 | "x86_64": ["darwin64-x86_64-cc", "enable-ec_nistp_64_gcc_128"], |
| 810 | "ppc": ["darwin-ppc-cc"], |
| 811 | "ppc64": ["darwin64-ppc-cc"], |
| 812 | } |
| 813 | configure_opts = [ |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 814 | "no-idea", |
| 815 | "no-mdc2", |
| 816 | "no-rc5", |
| 817 | "no-zlib", |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 818 | "no-ssl3", |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 819 | # "enable-unit-test", |
| 820 | "shared", |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 821 | "--prefix=%s"%os.path.join("/", *FW_VERSION_PREFIX), |
Ned Deily | dde4f63 | 2016-09-12 09:39:23 -0400 | [diff] [blame] | 822 | "--openssldir=%s"%os.path.join("/", *FW_SSL_DIRECTORY), |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 823 | ] |
| 824 | if no_asm: |
| 825 | configure_opts.append("no-asm") |
| 826 | runCommand(" ".join(["perl", "Configure"] |
| 827 | + arch_opts[arch] + configure_opts)) |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 828 | runCommand("make depend") |
| 829 | runCommand("make all") |
| 830 | runCommand("make install_sw DESTDIR=%s"%shellQuote(archbase)) |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 831 | # runCommand("make test") |
| 832 | return |
| 833 | |
| 834 | srcdir = os.getcwd() |
| 835 | universalbase = os.path.join(srcdir, "..", |
| 836 | os.path.basename(srcdir) + "-universal") |
| 837 | os.mkdir(universalbase) |
| 838 | archbasefws = [] |
| 839 | for arch in archList: |
| 840 | # fresh copy of the source tree |
| 841 | archsrc = os.path.join(universalbase, arch, "src") |
| 842 | shutil.copytree(srcdir, archsrc, symlinks=True) |
| 843 | # install base for this arch |
| 844 | archbase = os.path.join(universalbase, arch, "root") |
| 845 | os.mkdir(archbase) |
| 846 | # Python framework base within install_prefix: |
| 847 | # the build will install into this framework.. |
| 848 | # This is to ensure that the resulting shared libs have |
| 849 | # the desired real install paths built into them. |
| 850 | archbasefw = os.path.join(archbase, *FW_VERSION_PREFIX) |
| 851 | |
| 852 | # build one architecture |
| 853 | os.chdir(archsrc) |
| 854 | build_openssl_arch(archbase, arch) |
| 855 | os.chdir(srcdir) |
| 856 | archbasefws.append(archbasefw) |
| 857 | |
| 858 | # copy arch-independent files from last build into the basedir framework |
| 859 | basefw = os.path.join(basedir, *FW_VERSION_PREFIX) |
| 860 | shutil.copytree( |
| 861 | os.path.join(archbasefw, "include", "openssl"), |
| 862 | os.path.join(basefw, "include", "openssl") |
| 863 | ) |
| 864 | |
| 865 | shlib_version_number = grepValue(os.path.join(archsrc, "Makefile"), |
| 866 | "SHLIB_VERSION_NUMBER") |
| 867 | # e.g. -> "1.0.0" |
| 868 | libcrypto = "libcrypto.dylib" |
| 869 | libcrypto_versioned = libcrypto.replace(".", "."+shlib_version_number+".") |
| 870 | # e.g. -> "libcrypto.1.0.0.dylib" |
| 871 | libssl = "libssl.dylib" |
| 872 | libssl_versioned = libssl.replace(".", "."+shlib_version_number+".") |
| 873 | # e.g. -> "libssl.1.0.0.dylib" |
| 874 | |
| 875 | try: |
| 876 | os.mkdir(os.path.join(basefw, "lib")) |
| 877 | except OSError: |
| 878 | pass |
| 879 | |
| 880 | # merge the individual arch-dependent shared libs into a fat shared lib |
| 881 | archbasefws.insert(0, basefw) |
| 882 | for (lib_unversioned, lib_versioned) in [ |
| 883 | (libcrypto, libcrypto_versioned), |
| 884 | (libssl, libssl_versioned) |
| 885 | ]: |
| 886 | runCommand("lipo -create -output " + |
| 887 | " ".join(shellQuote( |
| 888 | os.path.join(fw, "lib", lib_versioned)) |
| 889 | for fw in archbasefws)) |
| 890 | # and create an unversioned symlink of it |
| 891 | os.symlink(lib_versioned, os.path.join(basefw, "lib", lib_unversioned)) |
| 892 | |
| 893 | # Create links in the temp include and lib dirs that will be injected |
| 894 | # into the Python build so that setup.py can find them while building |
| 895 | # and the versioned links so that the setup.py post-build import test |
| 896 | # does not fail. |
| 897 | relative_path = os.path.join("..", "..", "..", *FW_VERSION_PREFIX) |
| 898 | for fn in [ |
| 899 | ["include", "openssl"], |
| 900 | ["lib", libcrypto], |
| 901 | ["lib", libssl], |
| 902 | ["lib", libcrypto_versioned], |
| 903 | ["lib", libssl_versioned], |
| 904 | ]: |
| 905 | os.symlink( |
| 906 | os.path.join(relative_path, *fn), |
| 907 | os.path.join(basedir, "usr", "local", *fn) |
| 908 | ) |
| 909 | |
| 910 | return |
| 911 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 912 | def buildRecipe(recipe, basedir, archList): |
| 913 | """ |
| 914 | Build software using a recipe. This function does the |
| 915 | 'configure;make;make install' dance for C software, with a possibility |
| 916 | to customize this process, basically a poor-mans DarwinPorts. |
| 917 | """ |
| 918 | curdir = os.getcwd() |
| 919 | |
| 920 | name = recipe['name'] |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 921 | THIRD_PARTY_LIBS.append(name) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 922 | url = recipe['url'] |
| 923 | configure = recipe.get('configure', './configure') |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 924 | buildrecipe = recipe.get('buildrecipe', None) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 925 | install = recipe.get('install', 'make && make install DESTDIR=%s'%( |
| 926 | shellQuote(basedir))) |
| 927 | |
| 928 | archiveName = os.path.split(url)[-1] |
| 929 | sourceArchive = os.path.join(DEPSRC, archiveName) |
| 930 | |
| 931 | if not os.path.exists(DEPSRC): |
| 932 | os.mkdir(DEPSRC) |
| 933 | |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 934 | verifyThirdPartyFile(url, recipe['checksum'], sourceArchive) |
| 935 | print("Extracting archive for %s"%(name,)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 936 | buildDir=os.path.join(WORKDIR, '_bld') |
| 937 | if not os.path.exists(buildDir): |
| 938 | os.mkdir(buildDir) |
| 939 | |
| 940 | workDir = extractArchive(buildDir, sourceArchive) |
| 941 | os.chdir(workDir) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 942 | |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 943 | for patch in recipe.get('patches', ()): |
| 944 | if isinstance(patch, tuple): |
| 945 | url, checksum = patch |
| 946 | fn = os.path.join(DEPSRC, os.path.basename(url)) |
| 947 | verifyThirdPartyFile(url, checksum, fn) |
| 948 | else: |
| 949 | # patch is a file in the source directory |
| 950 | fn = os.path.join(curdir, patch) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 951 | runCommand('patch -p%s < %s'%(recipe.get('patchlevel', 1), |
| 952 | shellQuote(fn),)) |
| 953 | |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 954 | for patchscript in recipe.get('patchscripts', ()): |
| 955 | if isinstance(patchscript, tuple): |
| 956 | url, checksum = patchscript |
| 957 | fn = os.path.join(DEPSRC, os.path.basename(url)) |
| 958 | verifyThirdPartyFile(url, checksum, fn) |
| 959 | else: |
| 960 | # patch is a file in the source directory |
| 961 | fn = os.path.join(curdir, patchscript) |
| 962 | if fn.endswith('.bz2'): |
| 963 | runCommand('bunzip2 -fk %s' % shellQuote(fn)) |
| 964 | fn = fn[:-4] |
| 965 | runCommand('sh %s' % shellQuote(fn)) |
| 966 | os.unlink(fn) |
| 967 | |
Ned Deily | 94764b2 | 2013-10-27 19:49:29 -0700 | [diff] [blame] | 968 | if 'buildDir' in recipe: |
| 969 | os.chdir(recipe['buildDir']) |
| 970 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 971 | if configure is not None: |
| 972 | configure_args = [ |
| 973 | "--prefix=/usr/local", |
| 974 | "--enable-static", |
| 975 | "--disable-shared", |
| 976 | #"CPP=gcc -arch %s -E"%(' -arch '.join(archList,),), |
| 977 | ] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 978 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 979 | if 'configure_pre' in recipe: |
| 980 | args = list(recipe['configure_pre']) |
| 981 | if '--disable-static' in args: |
| 982 | configure_args.remove('--enable-static') |
| 983 | if '--enable-shared' in args: |
| 984 | configure_args.remove('--disable-shared') |
| 985 | configure_args.extend(args) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 986 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 987 | if recipe.get('useLDFlags', 1): |
| 988 | configure_args.extend([ |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 989 | "CFLAGS=%s-mmacosx-version-min=%s -arch %s " |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 990 | "-I%s/usr/local/include"%( |
| 991 | recipe.get('extra_cflags', ''), |
| 992 | DEPTARGET, |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 993 | ' -arch '.join(archList), |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 994 | shellQuote(basedir)[1:-1],), |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 995 | "LDFLAGS=-mmacosx-version-min=%s -L%s/usr/local/lib -arch %s"%( |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 996 | DEPTARGET, |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 997 | shellQuote(basedir)[1:-1], |
| 998 | ' -arch '.join(archList)), |
| 999 | ]) |
| 1000 | else: |
| 1001 | configure_args.extend([ |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 1002 | "CFLAGS=%s-mmacosx-version-min=%s -arch %s " |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1003 | "-I%s/usr/local/include"%( |
| 1004 | recipe.get('extra_cflags', ''), |
| 1005 | DEPTARGET, |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1006 | ' -arch '.join(archList), |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1007 | shellQuote(basedir)[1:-1],), |
| 1008 | ]) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1009 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1010 | if 'configure_post' in recipe: |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1011 | configure_args = configure_args + list(recipe['configure_post']) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1012 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1013 | configure_args.insert(0, configure) |
| 1014 | configure_args = [ shellQuote(a) for a in configure_args ] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1015 | |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1016 | print("Running configure for %s"%(name,)) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1017 | runCommand(' '.join(configure_args) + ' 2>&1') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1018 | |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 1019 | if buildrecipe is not None: |
| 1020 | # call special-case build recipe, e.g. for openssl |
| 1021 | buildrecipe(basedir, archList) |
| 1022 | |
| 1023 | if install is not None: |
| 1024 | print("Running install for %s"%(name,)) |
| 1025 | runCommand('{ ' + install + ' ;} 2>&1') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1026 | |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1027 | print("Done %s"%(name,)) |
| 1028 | print("") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1029 | |
| 1030 | os.chdir(curdir) |
| 1031 | |
| 1032 | def buildLibraries(): |
| 1033 | """ |
| 1034 | Build our dependencies into $WORKDIR/libraries/usr/local |
| 1035 | """ |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1036 | print("") |
| 1037 | print("Building required libraries") |
| 1038 | print("") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1039 | universal = os.path.join(WORKDIR, 'libraries') |
| 1040 | os.mkdir(universal) |
| 1041 | os.makedirs(os.path.join(universal, 'usr', 'local', 'lib')) |
| 1042 | os.makedirs(os.path.join(universal, 'usr', 'local', 'include')) |
| 1043 | |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1044 | for recipe in library_recipes(): |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1045 | buildRecipe(recipe, universal, ARCHLIST) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1046 | |
| 1047 | |
| 1048 | |
| 1049 | def buildPythonDocs(): |
Ronald Oussoren | 207b4c2 | 2009-03-30 17:20:30 +0000 | [diff] [blame] | 1050 | # This stores the documentation as Resources/English.lproj/Documentation |
Mike | 53f7a7c | 2017-12-14 14:04:53 +0300 | [diff] [blame] | 1051 | # inside the framework. pydoc and IDLE will pick it up there. |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1052 | print("Install python documentation") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1053 | rootDir = os.path.join(WORKDIR, '_root') |
Ronald Oussoren | 207b4c2 | 2009-03-30 17:20:30 +0000 | [diff] [blame] | 1054 | buildDir = os.path.join('../../Doc') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1055 | docdir = os.path.join(rootDir, 'pydocs') |
Ronald Oussoren | 207b4c2 | 2009-03-30 17:20:30 +0000 | [diff] [blame] | 1056 | curDir = os.getcwd() |
| 1057 | os.chdir(buildDir) |
Ned Deily | 1ff32a9 | 2014-09-05 15:57:05 -0700 | [diff] [blame] | 1058 | runCommand('make clean') |
Ned Deily | 4c7532e | 2017-07-23 16:39:54 -0400 | [diff] [blame] | 1059 | # Create virtual environment for docs builds with blurb and sphinx |
| 1060 | runCommand('make venv') |
| 1061 | runCommand('make html PYTHON=venv/bin/python') |
Ronald Oussoren | 207b4c2 | 2009-03-30 17:20:30 +0000 | [diff] [blame] | 1062 | os.chdir(curDir) |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1063 | if not os.path.exists(docdir): |
| 1064 | os.mkdir(docdir) |
Ronald Oussoren | f84d7e9 | 2009-05-19 11:27:25 +0000 | [diff] [blame] | 1065 | os.rename(os.path.join(buildDir, 'build', 'html'), docdir) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1066 | |
| 1067 | |
| 1068 | def buildPython(): |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1069 | print("Building a universal python for %s architectures" % UNIVERSALARCHS) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1070 | |
| 1071 | buildDir = os.path.join(WORKDIR, '_bld', 'python') |
| 1072 | rootDir = os.path.join(WORKDIR, '_root') |
| 1073 | |
| 1074 | if os.path.exists(buildDir): |
| 1075 | shutil.rmtree(buildDir) |
| 1076 | if os.path.exists(rootDir): |
| 1077 | shutil.rmtree(rootDir) |
Ned Deily | 4f7ff78 | 2011-01-15 05:29:12 +0000 | [diff] [blame] | 1078 | os.makedirs(buildDir) |
| 1079 | os.makedirs(rootDir) |
| 1080 | os.makedirs(os.path.join(rootDir, 'empty-dir')) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1081 | curdir = os.getcwd() |
| 1082 | os.chdir(buildDir) |
| 1083 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1084 | # Extract the version from the configure file, needed to calculate |
| 1085 | # several paths. |
| 1086 | version = getVersion() |
| 1087 | |
Ronald Oussoren | ac4b39f | 2009-03-30 20:05:35 +0000 | [diff] [blame] | 1088 | # Since the extra libs are not in their installed framework location |
| 1089 | # during the build, augment the library path so that the interpreter |
| 1090 | # will find them during its extension import sanity checks. |
| 1091 | os.environ['DYLD_LIBRARY_PATH'] = os.path.join(WORKDIR, |
| 1092 | 'libraries', 'usr', 'local', 'lib') |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1093 | print("Running configure...") |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 1094 | runCommand("%s -C --enable-framework --enable-universalsdk=/ " |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1095 | "--with-universal-archs=%s " |
| 1096 | "%s " |
Ned Deily | 41ab6c3 | 2013-11-22 22:25:43 -0800 | [diff] [blame] | 1097 | "%s " |
Ned Deily | 1ca2ffd | 2018-01-30 17:29:53 -0500 | [diff] [blame] | 1098 | "%s " |
| 1099 | "%s " |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1100 | "LDFLAGS='-g -L%s/libraries/usr/local/lib' " |
Ned Deily | 4b7a023 | 2013-10-25 00:46:02 -0700 | [diff] [blame] | 1101 | "CFLAGS='-g -I%s/libraries/usr/local/include' 2>&1"%( |
Ned Deily | 8c9bb72 | 2018-01-30 07:42:14 -0500 | [diff] [blame] | 1102 | shellQuote(os.path.join(SRCDIR, 'configure')), |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1103 | UNIVERSALARCHS, |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1104 | (' ', '--with-computed-gotos ')[PYTHON_3], |
Ned Deily | ed73010 | 2014-11-14 18:55:05 -0800 | [diff] [blame] | 1105 | (' ', '--without-ensurepip ')[PYTHON_3], |
Ned Deily | 1ca2ffd | 2018-01-30 17:29:53 -0500 | [diff] [blame] | 1106 | (' ', "--with-tcltk-includes='-I%s/libraries/usr/local/include'"%( |
| 1107 | shellQuote(WORKDIR)[1:-1],))[internalTk()], |
| 1108 | (' ', "--with-tcltk-libs='-L%s/libraries/usr/local/lib -ltcl8.6 -ltk8.6'"%( |
| 1109 | shellQuote(WORKDIR)[1:-1],))[internalTk()], |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1110 | shellQuote(WORKDIR)[1:-1], |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1111 | shellQuote(WORKDIR)[1:-1])) |
| 1112 | |
Ned Deily | b364d9f | 2017-07-24 04:58:43 -0400 | [diff] [blame] | 1113 | # Look for environment value BUILDINSTALLER_BUILDPYTHON_MAKE_EXTRAS |
| 1114 | # and, if defined, append its value to the make command. This allows |
| 1115 | # us to pass in version control tags, like GITTAG, to a build from a |
| 1116 | # tarball rather than from a vcs checkout, thus eliminating the need |
| 1117 | # to have a working copy of the vcs program on the build machine. |
| 1118 | # |
| 1119 | # A typical use might be: |
| 1120 | # export BUILDINSTALLER_BUILDPYTHON_MAKE_EXTRAS=" \ |
| 1121 | # GITVERSION='echo 123456789a' \ |
| 1122 | # GITTAG='echo v3.6.0' \ |
| 1123 | # GITBRANCH='echo 3.6'" |
| 1124 | |
| 1125 | make_extras = os.getenv("BUILDINSTALLER_BUILDPYTHON_MAKE_EXTRAS") |
| 1126 | if make_extras: |
| 1127 | make_cmd = "make " + make_extras |
| 1128 | else: |
| 1129 | make_cmd = "make" |
| 1130 | print("Running " + make_cmd) |
| 1131 | runCommand(make_cmd) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1132 | |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1133 | print("Running make install") |
Ronald Oussoren | f84d7e9 | 2009-05-19 11:27:25 +0000 | [diff] [blame] | 1134 | runCommand("make install DESTDIR=%s"%( |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1135 | shellQuote(rootDir))) |
| 1136 | |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1137 | print("Running make frameworkinstallextras") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1138 | runCommand("make frameworkinstallextras DESTDIR=%s"%( |
| 1139 | shellQuote(rootDir))) |
| 1140 | |
Ronald Oussoren | ac4b39f | 2009-03-30 20:05:35 +0000 | [diff] [blame] | 1141 | del os.environ['DYLD_LIBRARY_PATH'] |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1142 | print("Copying required shared libraries") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1143 | if os.path.exists(os.path.join(WORKDIR, 'libraries', 'Library')): |
Ned Deily | 1ca2ffd | 2018-01-30 17:29:53 -0500 | [diff] [blame] | 1144 | build_lib_dir = os.path.join( |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1145 | WORKDIR, 'libraries', 'Library', 'Frameworks', |
Ned Deily | 1ca2ffd | 2018-01-30 17:29:53 -0500 | [diff] [blame] | 1146 | 'Python.framework', 'Versions', getVersion(), 'lib') |
| 1147 | fw_lib_dir = os.path.join( |
| 1148 | WORKDIR, '_root', 'Library', 'Frameworks', |
| 1149 | 'Python.framework', 'Versions', getVersion(), 'lib') |
| 1150 | if internalTk(): |
| 1151 | # move Tcl and Tk pkgconfig files |
| 1152 | runCommand("mv %s/pkgconfig/* %s/pkgconfig"%( |
| 1153 | shellQuote(build_lib_dir), |
| 1154 | shellQuote(fw_lib_dir) )) |
| 1155 | runCommand("rm -r %s/pkgconfig"%( |
| 1156 | shellQuote(build_lib_dir), )) |
| 1157 | runCommand("mv %s/* %s"%( |
| 1158 | shellQuote(build_lib_dir), |
| 1159 | shellQuote(fw_lib_dir) )) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1160 | |
Ned Deily | dde4f63 | 2016-09-12 09:39:23 -0400 | [diff] [blame] | 1161 | frmDir = os.path.join(rootDir, 'Library', 'Frameworks', 'Python.framework') |
| 1162 | frmDirVersioned = os.path.join(frmDir, 'Versions', version) |
| 1163 | path_to_lib = os.path.join(frmDirVersioned, 'lib', 'python%s'%(version,)) |
| 1164 | # create directory for OpenSSL certificates |
| 1165 | sslDir = os.path.join(frmDirVersioned, 'etc', 'openssl') |
| 1166 | os.makedirs(sslDir) |
Ned Deily | 050fcd5 | 2013-10-26 03:16:44 -0700 | [diff] [blame] | 1167 | |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1168 | print("Fix file modes") |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 1169 | gid = grp.getgrnam('admin').gr_gid |
| 1170 | |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1171 | shared_lib_error = False |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1172 | for dirpath, dirnames, filenames in os.walk(frmDir): |
| 1173 | for dn in dirnames: |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1174 | os.chmod(os.path.join(dirpath, dn), STAT_0o775) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 1175 | os.chown(os.path.join(dirpath, dn), -1, gid) |
| 1176 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1177 | for fn in filenames: |
| 1178 | if os.path.islink(fn): |
| 1179 | continue |
| 1180 | |
| 1181 | # "chmod g+w $fn" |
| 1182 | p = os.path.join(dirpath, fn) |
| 1183 | st = os.stat(p) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 1184 | os.chmod(p, stat.S_IMODE(st.st_mode) | stat.S_IWGRP) |
| 1185 | os.chown(p, -1, gid) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1186 | |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1187 | if fn in EXPECTED_SHARED_LIBS: |
| 1188 | # check to see that this file was linked with the |
| 1189 | # expected library path and version |
| 1190 | data = captureCommand("otool -L %s" % shellQuote(p)) |
| 1191 | for sl in EXPECTED_SHARED_LIBS[fn]: |
| 1192 | if ("\t%s " % sl) not in data: |
| 1193 | print("Expected shared lib %s was not linked with %s" |
| 1194 | % (sl, p)) |
| 1195 | shared_lib_error = True |
| 1196 | |
| 1197 | if shared_lib_error: |
| 1198 | fatal("Unexpected shared library errors.") |
| 1199 | |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 1200 | if PYTHON_3: |
| 1201 | LDVERSION=None |
| 1202 | VERSION=None |
| 1203 | ABIFLAGS=None |
Ronald Oussoren | 0499d0b | 2010-12-07 14:41:05 +0000 | [diff] [blame] | 1204 | |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 1205 | fp = open(os.path.join(buildDir, 'Makefile'), 'r') |
Ronald Oussoren | 0499d0b | 2010-12-07 14:41:05 +0000 | [diff] [blame] | 1206 | for ln in fp: |
| 1207 | if ln.startswith('VERSION='): |
| 1208 | VERSION=ln.split()[1] |
| 1209 | if ln.startswith('ABIFLAGS='): |
| 1210 | ABIFLAGS=ln.split()[1] |
Ronald Oussoren | 0499d0b | 2010-12-07 14:41:05 +0000 | [diff] [blame] | 1211 | if ln.startswith('LDVERSION='): |
| 1212 | LDVERSION=ln.split()[1] |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 1213 | fp.close() |
Ronald Oussoren | 0499d0b | 2010-12-07 14:41:05 +0000 | [diff] [blame] | 1214 | |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 1215 | LDVERSION = LDVERSION.replace('$(VERSION)', VERSION) |
| 1216 | LDVERSION = LDVERSION.replace('$(ABIFLAGS)', ABIFLAGS) |
| 1217 | config_suffix = '-' + LDVERSION |
Ned Deily | 652bad4 | 2016-08-15 14:37:14 -0400 | [diff] [blame] | 1218 | if getVersionMajorMinor() >= (3, 6): |
| 1219 | config_suffix = config_suffix + '-darwin' |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 1220 | else: |
| 1221 | config_suffix = '' # Python 2.x |
Ronald Oussoren | 0499d0b | 2010-12-07 14:41:05 +0000 | [diff] [blame] | 1222 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1223 | # We added some directories to the search path during the configure |
| 1224 | # phase. Remove those because those directories won't be there on |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1225 | # the end-users system. Also remove the directories from _sysconfigdata.py |
| 1226 | # (added in 3.3) if it exists. |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1227 | |
Ned Deily | a4f6b00 | 2013-10-25 00:47:38 -0700 | [diff] [blame] | 1228 | include_path = '-I%s/libraries/usr/local/include' % (WORKDIR,) |
| 1229 | lib_path = '-L%s/libraries/usr/local/lib' % (WORKDIR,) |
| 1230 | |
Ned Deily | a4f6b00 | 2013-10-25 00:47:38 -0700 | [diff] [blame] | 1231 | # fix Makefile |
| 1232 | path = os.path.join(path_to_lib, 'config' + config_suffix, 'Makefile') |
| 1233 | fp = open(path, 'r') |
| 1234 | data = fp.read() |
| 1235 | fp.close() |
| 1236 | |
| 1237 | for p in (include_path, lib_path): |
| 1238 | data = data.replace(" " + p, '') |
| 1239 | data = data.replace(p + " ", '') |
| 1240 | |
| 1241 | fp = open(path, 'w') |
| 1242 | fp.write(data) |
| 1243 | fp.close() |
| 1244 | |
Ned Deily | 652bad4 | 2016-08-15 14:37:14 -0400 | [diff] [blame] | 1245 | # fix _sysconfigdata |
Ned Deily | a4f6b00 | 2013-10-25 00:47:38 -0700 | [diff] [blame] | 1246 | # |
| 1247 | # TODO: make this more robust! test_sysconfig_module of |
| 1248 | # distutils.tests.test_sysconfig.SysconfigTestCase tests that |
| 1249 | # the output from get_config_var in both sysconfig and |
| 1250 | # distutils.sysconfig is exactly the same for both CFLAGS and |
| 1251 | # LDFLAGS. The fixing up is now complicated by the pretty |
| 1252 | # printing in _sysconfigdata.py. Also, we are using the |
| 1253 | # pprint from the Python running the installer build which |
| 1254 | # may not cosmetically format the same as the pprint in the Python |
| 1255 | # being built (and which is used to originally generate |
| 1256 | # _sysconfigdata.py). |
| 1257 | |
| 1258 | import pprint |
Ned Deily | 652bad4 | 2016-08-15 14:37:14 -0400 | [diff] [blame] | 1259 | if getVersionMajorMinor() >= (3, 6): |
Zachary Ware | c4b53af | 2016-09-09 17:59:49 -0700 | [diff] [blame] | 1260 | # XXX this is extra-fragile |
| 1261 | path = os.path.join(path_to_lib, '_sysconfigdata_m_darwin_darwin.py') |
Ned Deily | 652bad4 | 2016-08-15 14:37:14 -0400 | [diff] [blame] | 1262 | else: |
| 1263 | path = os.path.join(path_to_lib, '_sysconfigdata.py') |
| 1264 | fp = open(path, 'r') |
| 1265 | data = fp.read() |
| 1266 | fp.close() |
| 1267 | # create build_time_vars dict |
| 1268 | exec(data) |
| 1269 | vars = {} |
| 1270 | for k, v in build_time_vars.items(): |
| 1271 | if type(v) == type(''): |
| 1272 | for p in (include_path, lib_path): |
| 1273 | v = v.replace(' ' + p, '') |
| 1274 | v = v.replace(p + ' ', '') |
| 1275 | vars[k] = v |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1276 | |
Ned Deily | 652bad4 | 2016-08-15 14:37:14 -0400 | [diff] [blame] | 1277 | fp = open(path, 'w') |
| 1278 | # duplicated from sysconfig._generate_posix_vars() |
| 1279 | fp.write('# system configuration generated and used by' |
| 1280 | ' the sysconfig module\n') |
| 1281 | fp.write('build_time_vars = ') |
| 1282 | pprint.pprint(vars, stream=fp) |
| 1283 | fp.close() |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1284 | |
| 1285 | # Add symlinks in /usr/local/bin, using relative links |
| 1286 | usr_local_bin = os.path.join(rootDir, 'usr', 'local', 'bin') |
| 1287 | to_framework = os.path.join('..', '..', '..', 'Library', 'Frameworks', |
| 1288 | 'Python.framework', 'Versions', version, 'bin') |
| 1289 | if os.path.exists(usr_local_bin): |
| 1290 | shutil.rmtree(usr_local_bin) |
| 1291 | os.makedirs(usr_local_bin) |
| 1292 | for fn in os.listdir( |
| 1293 | os.path.join(frmDir, 'Versions', version, 'bin')): |
| 1294 | os.symlink(os.path.join(to_framework, fn), |
| 1295 | os.path.join(usr_local_bin, fn)) |
| 1296 | |
| 1297 | os.chdir(curdir) |
| 1298 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1299 | if PYTHON_3: |
Ezio Melotti | 7c4a7e6 | 2013-08-26 01:32:56 +0300 | [diff] [blame] | 1300 | # Remove the 'Current' link, that way we don't accidentally mess |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1301 | # with an already installed version of python 2 |
| 1302 | os.unlink(os.path.join(rootDir, 'Library', 'Frameworks', |
| 1303 | 'Python.framework', 'Versions', 'Current')) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1304 | |
| 1305 | def patchFile(inPath, outPath): |
| 1306 | data = fileContents(inPath) |
| 1307 | data = data.replace('$FULL_VERSION', getFullVersion()) |
| 1308 | data = data.replace('$VERSION', getVersion()) |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1309 | data = data.replace('$MACOSX_DEPLOYMENT_TARGET', ''.join((DEPTARGET, ' or later'))) |
Ronald Oussoren | d010329 | 2010-10-20 12:56:56 +0000 | [diff] [blame] | 1310 | data = data.replace('$ARCHITECTURES', ", ".join(universal_opts_map[UNIVERSALARCHS])) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1311 | data = data.replace('$INSTALL_SIZE', installSize()) |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 1312 | data = data.replace('$THIRD_PARTY_LIBS', "\\\n".join(THIRD_PARTY_LIBS)) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1313 | |
| 1314 | # This one is not handy as a template variable |
| 1315 | data = data.replace('$PYTHONFRAMEWORKINSTALLDIR', '/Library/Frameworks/Python.framework') |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1316 | fp = open(outPath, 'w') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1317 | fp.write(data) |
| 1318 | fp.close() |
| 1319 | |
| 1320 | def patchScript(inPath, outPath): |
Ned Deily | ed73010 | 2014-11-14 18:55:05 -0800 | [diff] [blame] | 1321 | major, minor = getVersionMajorMinor() |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1322 | data = fileContents(inPath) |
Ned Deily | ed73010 | 2014-11-14 18:55:05 -0800 | [diff] [blame] | 1323 | data = data.replace('@PYMAJOR@', str(major)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1324 | data = data.replace('@PYVER@', getVersion()) |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1325 | fp = open(outPath, 'w') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1326 | fp.write(data) |
| 1327 | fp.close() |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1328 | os.chmod(outPath, STAT_0o755) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1329 | |
| 1330 | |
| 1331 | |
| 1332 | def packageFromRecipe(targetDir, recipe): |
| 1333 | curdir = os.getcwd() |
| 1334 | try: |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 1335 | # The major version (such as 2.5) is included in the package name |
| 1336 | # because having two version of python installed at the same time is |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1337 | # common. |
| 1338 | pkgname = '%s-%s'%(recipe['name'], getVersion()) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1339 | srcdir = recipe.get('source') |
| 1340 | pkgroot = recipe.get('topdir', srcdir) |
| 1341 | postflight = recipe.get('postflight') |
| 1342 | readme = textwrap.dedent(recipe['readme']) |
| 1343 | isRequired = recipe.get('required', True) |
| 1344 | |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1345 | print("- building package %s"%(pkgname,)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1346 | |
| 1347 | # Substitute some variables |
| 1348 | textvars = dict( |
| 1349 | VER=getVersion(), |
| 1350 | FULLVER=getFullVersion(), |
| 1351 | ) |
| 1352 | readme = readme % textvars |
| 1353 | |
| 1354 | if pkgroot is not None: |
| 1355 | pkgroot = pkgroot % textvars |
| 1356 | else: |
| 1357 | pkgroot = '/' |
| 1358 | |
| 1359 | if srcdir is not None: |
| 1360 | srcdir = os.path.join(WORKDIR, '_root', srcdir[1:]) |
| 1361 | srcdir = srcdir % textvars |
| 1362 | |
| 1363 | if postflight is not None: |
| 1364 | postflight = os.path.abspath(postflight) |
| 1365 | |
| 1366 | packageContents = os.path.join(targetDir, pkgname + '.pkg', 'Contents') |
| 1367 | os.makedirs(packageContents) |
| 1368 | |
| 1369 | if srcdir is not None: |
| 1370 | os.chdir(srcdir) |
| 1371 | runCommand("pax -wf %s . 2>&1"%(shellQuote(os.path.join(packageContents, 'Archive.pax')),)) |
| 1372 | runCommand("gzip -9 %s 2>&1"%(shellQuote(os.path.join(packageContents, 'Archive.pax')),)) |
| 1373 | runCommand("mkbom . %s 2>&1"%(shellQuote(os.path.join(packageContents, 'Archive.bom')),)) |
| 1374 | |
| 1375 | fn = os.path.join(packageContents, 'PkgInfo') |
| 1376 | fp = open(fn, 'w') |
| 1377 | fp.write('pmkrpkg1') |
| 1378 | fp.close() |
| 1379 | |
| 1380 | rsrcDir = os.path.join(packageContents, "Resources") |
| 1381 | os.mkdir(rsrcDir) |
| 1382 | fp = open(os.path.join(rsrcDir, 'ReadMe.txt'), 'w') |
| 1383 | fp.write(readme) |
| 1384 | fp.close() |
| 1385 | |
| 1386 | if postflight is not None: |
| 1387 | patchScript(postflight, os.path.join(rsrcDir, 'postflight')) |
| 1388 | |
| 1389 | vers = getFullVersion() |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1390 | major, minor = getVersionMajorMinor() |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1391 | pl = Plist( |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1392 | CFBundleGetInfoString="Python.%s %s"%(pkgname, vers,), |
| 1393 | CFBundleIdentifier='org.python.Python.%s'%(pkgname,), |
| 1394 | CFBundleName='Python.%s'%(pkgname,), |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1395 | CFBundleShortVersionString=vers, |
| 1396 | IFMajorVersion=major, |
| 1397 | IFMinorVersion=minor, |
| 1398 | IFPkgFormatVersion=0.10000000149011612, |
| 1399 | IFPkgFlagAllowBackRev=False, |
| 1400 | IFPkgFlagAuthorizationAction="RootAuthorization", |
| 1401 | IFPkgFlagDefaultLocation=pkgroot, |
| 1402 | IFPkgFlagFollowLinks=True, |
| 1403 | IFPkgFlagInstallFat=True, |
| 1404 | IFPkgFlagIsRequired=isRequired, |
| 1405 | IFPkgFlagOverwritePermissions=False, |
| 1406 | IFPkgFlagRelocatable=False, |
| 1407 | IFPkgFlagRestartAction="NoRestart", |
| 1408 | IFPkgFlagRootVolumeOnly=True, |
| 1409 | IFPkgFlagUpdateInstalledLangauges=False, |
| 1410 | ) |
| 1411 | writePlist(pl, os.path.join(packageContents, 'Info.plist')) |
| 1412 | |
| 1413 | pl = Plist( |
| 1414 | IFPkgDescriptionDescription=readme, |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1415 | IFPkgDescriptionTitle=recipe.get('long_name', "Python.%s"%(pkgname,)), |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1416 | IFPkgDescriptionVersion=vers, |
| 1417 | ) |
| 1418 | writePlist(pl, os.path.join(packageContents, 'Resources', 'Description.plist')) |
| 1419 | |
| 1420 | finally: |
| 1421 | os.chdir(curdir) |
| 1422 | |
| 1423 | |
| 1424 | def makeMpkgPlist(path): |
| 1425 | |
| 1426 | vers = getFullVersion() |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1427 | major, minor = getVersionMajorMinor() |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1428 | |
| 1429 | pl = Plist( |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1430 | CFBundleGetInfoString="Python %s"%(vers,), |
| 1431 | CFBundleIdentifier='org.python.Python', |
| 1432 | CFBundleName='Python', |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1433 | CFBundleShortVersionString=vers, |
| 1434 | IFMajorVersion=major, |
| 1435 | IFMinorVersion=minor, |
| 1436 | IFPkgFlagComponentDirectory="Contents/Packages", |
| 1437 | IFPkgFlagPackageList=[ |
| 1438 | dict( |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1439 | IFPkgFlagPackageLocation='%s-%s.pkg'%(item['name'], getVersion()), |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1440 | IFPkgFlagPackageSelection=item.get('selected', 'selected'), |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1441 | ) |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1442 | for item in pkg_recipes() |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1443 | ], |
| 1444 | IFPkgFormatVersion=0.10000000149011612, |
| 1445 | IFPkgFlagBackgroundScaling="proportional", |
| 1446 | IFPkgFlagBackgroundAlignment="left", |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1447 | IFPkgFlagAuthorizationAction="RootAuthorization", |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1448 | ) |
| 1449 | |
| 1450 | writePlist(pl, path) |
| 1451 | |
| 1452 | |
| 1453 | def buildInstaller(): |
| 1454 | |
| 1455 | # Zap all compiled files |
| 1456 | for dirpath, _, filenames in os.walk(os.path.join(WORKDIR, '_root')): |
| 1457 | for fn in filenames: |
| 1458 | if fn.endswith('.pyc') or fn.endswith('.pyo'): |
| 1459 | os.unlink(os.path.join(dirpath, fn)) |
| 1460 | |
| 1461 | outdir = os.path.join(WORKDIR, 'installer') |
| 1462 | if os.path.exists(outdir): |
| 1463 | shutil.rmtree(outdir) |
| 1464 | os.mkdir(outdir) |
| 1465 | |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1466 | pkgroot = os.path.join(outdir, 'Python.mpkg', 'Contents') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1467 | pkgcontents = os.path.join(pkgroot, 'Packages') |
| 1468 | os.makedirs(pkgcontents) |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1469 | for recipe in pkg_recipes(): |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1470 | packageFromRecipe(pkgcontents, recipe) |
| 1471 | |
| 1472 | rsrcDir = os.path.join(pkgroot, 'Resources') |
| 1473 | |
| 1474 | fn = os.path.join(pkgroot, 'PkgInfo') |
| 1475 | fp = open(fn, 'w') |
| 1476 | fp.write('pmkrpkg1') |
| 1477 | fp.close() |
| 1478 | |
| 1479 | os.mkdir(rsrcDir) |
| 1480 | |
| 1481 | makeMpkgPlist(os.path.join(pkgroot, 'Info.plist')) |
| 1482 | pl = Plist( |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1483 | IFPkgDescriptionTitle="Python", |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1484 | IFPkgDescriptionVersion=getVersion(), |
| 1485 | ) |
| 1486 | |
| 1487 | writePlist(pl, os.path.join(pkgroot, 'Resources', 'Description.plist')) |
| 1488 | for fn in os.listdir('resources'): |
| 1489 | if fn == '.svn': continue |
| 1490 | if fn.endswith('.jpg'): |
| 1491 | shutil.copy(os.path.join('resources', fn), os.path.join(rsrcDir, fn)) |
| 1492 | else: |
| 1493 | patchFile(os.path.join('resources', fn), os.path.join(rsrcDir, fn)) |
| 1494 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1495 | |
| 1496 | def installSize(clear=False, _saved=[]): |
| 1497 | if clear: |
| 1498 | del _saved[:] |
| 1499 | if not _saved: |
| 1500 | data = captureCommand("du -ks %s"%( |
| 1501 | shellQuote(os.path.join(WORKDIR, '_root')))) |
| 1502 | _saved.append("%d"%((0.5 + (int(data.split()[0]) / 1024.0)),)) |
| 1503 | return _saved[0] |
| 1504 | |
| 1505 | |
| 1506 | def buildDMG(): |
| 1507 | """ |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 1508 | Create DMG containing the rootDir. |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1509 | """ |
| 1510 | outdir = os.path.join(WORKDIR, 'diskimage') |
| 1511 | if os.path.exists(outdir): |
| 1512 | shutil.rmtree(outdir) |
| 1513 | |
| 1514 | imagepath = os.path.join(outdir, |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1515 | 'python-%s-macosx%s'%(getFullVersion(),DEPTARGET)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1516 | if INCLUDE_TIMESTAMP: |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1517 | imagepath = imagepath + '-%04d-%02d-%02d'%(time.localtime()[:3]) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1518 | imagepath = imagepath + '.dmg' |
| 1519 | |
| 1520 | os.mkdir(outdir) |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1521 | volname='Python %s'%(getFullVersion()) |
| 1522 | runCommand("hdiutil create -format UDRW -volname %s -srcfolder %s %s"%( |
| 1523 | shellQuote(volname), |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1524 | shellQuote(os.path.join(WORKDIR, 'installer')), |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1525 | shellQuote(imagepath + ".tmp.dmg" ))) |
| 1526 | |
Ned Deily | fc6aa28 | 2018-05-02 01:41:15 -0400 | [diff] [blame] | 1527 | # Try to mitigate race condition in certain versions of macOS, e.g. 10.9, |
| 1528 | # when hdiutil fails with "Resource busy" |
| 1529 | |
| 1530 | time.sleep(10) |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1531 | |
| 1532 | if not os.path.exists(os.path.join(WORKDIR, "mnt")): |
| 1533 | os.mkdir(os.path.join(WORKDIR, "mnt")) |
| 1534 | runCommand("hdiutil attach %s -mountroot %s"%( |
| 1535 | shellQuote(imagepath + ".tmp.dmg"), shellQuote(os.path.join(WORKDIR, "mnt")))) |
| 1536 | |
| 1537 | # Custom icon for the DMG, shown when the DMG is mounted. |
| 1538 | shutil.copy("../Icons/Disk Image.icns", |
| 1539 | os.path.join(WORKDIR, "mnt", volname, ".VolumeIcon.icns")) |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1540 | runCommand("SetFile -a C %s/"%( |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1541 | shellQuote(os.path.join(WORKDIR, "mnt", volname)),)) |
| 1542 | |
| 1543 | runCommand("hdiutil detach %s"%(shellQuote(os.path.join(WORKDIR, "mnt", volname)))) |
| 1544 | |
| 1545 | setIcon(imagepath + ".tmp.dmg", "../Icons/Disk Image.icns") |
| 1546 | runCommand("hdiutil convert %s -format UDZO -o %s"%( |
| 1547 | shellQuote(imagepath + ".tmp.dmg"), shellQuote(imagepath))) |
| 1548 | setIcon(imagepath, "../Icons/Disk Image.icns") |
| 1549 | |
| 1550 | os.unlink(imagepath + ".tmp.dmg") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1551 | |
| 1552 | return imagepath |
| 1553 | |
| 1554 | |
| 1555 | def setIcon(filePath, icnsPath): |
| 1556 | """ |
| 1557 | Set the custom icon for the specified file or directory. |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1558 | """ |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1559 | |
Ronald Oussoren | 7005067 | 2010-04-30 15:00:26 +0000 | [diff] [blame] | 1560 | dirPath = os.path.normpath(os.path.dirname(__file__)) |
| 1561 | toolPath = os.path.join(dirPath, "seticon.app/Contents/MacOS/seticon") |
Ronald Oussoren | 207b4c2 | 2009-03-30 17:20:30 +0000 | [diff] [blame] | 1562 | if not os.path.exists(toolPath) or os.stat(toolPath).st_mtime < os.stat(dirPath + '/seticon.m').st_mtime: |
| 1563 | # NOTE: The tool is created inside an .app bundle, otherwise it won't work due |
| 1564 | # to connections to the window server. |
Ronald Oussoren | 7005067 | 2010-04-30 15:00:26 +0000 | [diff] [blame] | 1565 | appPath = os.path.join(dirPath, "seticon.app/Contents/MacOS") |
| 1566 | if not os.path.exists(appPath): |
| 1567 | os.makedirs(appPath) |
Ronald Oussoren | 207b4c2 | 2009-03-30 17:20:30 +0000 | [diff] [blame] | 1568 | runCommand("cc -o %s %s/seticon.m -framework Cocoa"%( |
| 1569 | shellQuote(toolPath), shellQuote(dirPath))) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1570 | |
Ronald Oussoren | 207b4c2 | 2009-03-30 17:20:30 +0000 | [diff] [blame] | 1571 | runCommand("%s %s %s"%(shellQuote(os.path.abspath(toolPath)), shellQuote(icnsPath), |
| 1572 | shellQuote(filePath))) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1573 | |
| 1574 | def main(): |
| 1575 | # First parse options and check if we can perform our work |
| 1576 | parseOptions() |
| 1577 | checkEnvironment() |
| 1578 | |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1579 | os.environ['MACOSX_DEPLOYMENT_TARGET'] = DEPTARGET |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1580 | os.environ['CC'] = CC |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1581 | os.environ['CXX'] = CXX |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1582 | |
| 1583 | if os.path.exists(WORKDIR): |
| 1584 | shutil.rmtree(WORKDIR) |
| 1585 | os.mkdir(WORKDIR) |
| 1586 | |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 1587 | os.environ['LC_ALL'] = 'C' |
| 1588 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1589 | # Then build third-party libraries such as sleepycat DB4. |
| 1590 | buildLibraries() |
| 1591 | |
| 1592 | # Now build python itself |
| 1593 | buildPython() |
Ronald Oussoren | 6bf6367 | 2009-03-31 13:25:17 +0000 | [diff] [blame] | 1594 | |
| 1595 | # And then build the documentation |
| 1596 | # Remove the Deployment Target from the shell |
| 1597 | # environment, it's no longer needed and |
| 1598 | # an unexpected build target can cause problems |
| 1599 | # when Sphinx and its dependencies need to |
| 1600 | # be (re-)installed. |
| 1601 | del os.environ['MACOSX_DEPLOYMENT_TARGET'] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1602 | buildPythonDocs() |
Ronald Oussoren | 6bf6367 | 2009-03-31 13:25:17 +0000 | [diff] [blame] | 1603 | |
| 1604 | |
| 1605 | # Prepare the applications folder |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 1606 | folder = os.path.join(WORKDIR, "_root", "Applications", "Python %s"%( |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1607 | getVersion(),)) |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 1608 | fn = os.path.join(folder, "License.rtf") |
| 1609 | patchFile("resources/License.rtf", fn) |
| 1610 | fn = os.path.join(folder, "ReadMe.rtf") |
| 1611 | patchFile("resources/ReadMe.rtf", fn) |
| 1612 | fn = os.path.join(folder, "Update Shell Profile.command") |
| 1613 | patchScript("scripts/postflight.patch-profile", fn) |
Ned Deily | dde4f63 | 2016-09-12 09:39:23 -0400 | [diff] [blame] | 1614 | fn = os.path.join(folder, "Install Certificates.command") |
| 1615 | patchScript("resources/install_certificates.command", fn) |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1616 | os.chmod(folder, STAT_0o755) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1617 | setIcon(folder, "../Icons/Python Folder.icns") |
| 1618 | |
| 1619 | # Create the installer |
| 1620 | buildInstaller() |
| 1621 | |
| 1622 | # And copy the readme into the directory containing the installer |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 1623 | patchFile('resources/ReadMe.rtf', |
| 1624 | os.path.join(WORKDIR, 'installer', 'ReadMe.rtf')) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1625 | |
| 1626 | # Ditto for the license file. |
Ned Deily | 5d3febf | 2014-12-13 00:17:46 -0800 | [diff] [blame] | 1627 | patchFile('resources/License.rtf', |
| 1628 | os.path.join(WORKDIR, 'installer', 'License.rtf')) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1629 | |
| 1630 | fp = open(os.path.join(WORKDIR, 'installer', 'Build.txt'), 'w') |
Ned Deily | 4a96a37 | 2013-01-29 00:08:32 -0800 | [diff] [blame] | 1631 | fp.write("# BUILD INFO\n") |
| 1632 | fp.write("# Date: %s\n" % time.ctime()) |
| 1633 | fp.write("# By: %s\n" % pwd.getpwuid(os.getuid()).pw_gecos) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1634 | fp.close() |
| 1635 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1636 | # And copy it to a DMG |
| 1637 | buildDMG() |
| 1638 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1639 | if __name__ == "__main__": |
| 1640 | main() |