Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 2 | """ |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 3 | This script is used to build "official" universal installers on Mac OS X. |
| 4 | It requires at least Mac OS X 10.4, Xcode 2.2 and the 10.4u SDK for |
| 5 | 32-bit builds. 64-bit or four-way universal builds require at least |
| 6 | OS X 10.5 and the 10.5 SDK. |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 7 | |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 8 | Please ensure that this script keeps working with Python 2.5, to avoid |
| 9 | bootstrap issues (/usr/bin/python is Python 2.5 on OSX 10.5). Sphinx, |
| 10 | which is used to build the documentation, currently requires at least |
| 11 | Python 2.4. |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 12 | |
| 13 | Usage: see USAGE variable in the script. |
| 14 | """ |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 15 | import platform, os, sys, getopt, textwrap, shutil, stat, time, pwd, grp |
| 16 | try: |
| 17 | import urllib2 as urllib_request |
| 18 | except ImportError: |
| 19 | import urllib.request as urllib_request |
| 20 | |
| 21 | STAT_0o755 = ( stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
| 22 | | stat.S_IRGRP | stat.S_IXGRP |
| 23 | | stat.S_IROTH | stat.S_IXOTH ) |
| 24 | |
| 25 | STAT_0o775 = ( stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
| 26 | | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP |
| 27 | | stat.S_IROTH | stat.S_IXOTH ) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 28 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 29 | INCLUDE_TIMESTAMP = 1 |
| 30 | VERBOSE = 1 |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 31 | |
| 32 | from plistlib import Plist |
| 33 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 34 | try: |
| 35 | from plistlib import writePlist |
| 36 | except ImportError: |
| 37 | # We're run using python2.3 |
| 38 | def writePlist(plist, path): |
| 39 | plist.write(path) |
| 40 | |
| 41 | def shellQuote(value): |
| 42 | """ |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 43 | 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] | 44 | a shell command. |
| 45 | """ |
| 46 | return "'%s'"%(value.replace("'", "'\"'\"'")) |
| 47 | |
| 48 | def grepValue(fn, variable): |
| 49 | variable = variable + '=' |
| 50 | for ln in open(fn, 'r'): |
| 51 | if ln.startswith(variable): |
| 52 | value = ln[len(variable):].strip() |
| 53 | return value[1:-1] |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 54 | raise RuntimeError("Cannot find variable %s" % variable[:-1]) |
| 55 | |
| 56 | _cache_getVersion = None |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 57 | |
| 58 | def getVersion(): |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 59 | global _cache_getVersion |
| 60 | if _cache_getVersion is None: |
| 61 | _cache_getVersion = grepValue( |
| 62 | os.path.join(SRCDIR, 'configure'), 'PACKAGE_VERSION') |
| 63 | return _cache_getVersion |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 64 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 65 | def getVersionTuple(): |
| 66 | return tuple([int(n) for n in getVersion().split('.')]) |
| 67 | |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 68 | def getVersionMajorMinor(): |
| 69 | return tuple([int(n) for n in getVersion().split('.', 2)]) |
| 70 | |
| 71 | _cache_getFullVersion = None |
| 72 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 73 | def getFullVersion(): |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 74 | global _cache_getFullVersion |
| 75 | if _cache_getFullVersion is not None: |
| 76 | return _cache_getFullVersion |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 77 | fn = os.path.join(SRCDIR, 'Include', 'patchlevel.h') |
| 78 | for ln in open(fn): |
| 79 | if 'PY_VERSION' in ln: |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 80 | _cache_getFullVersion = ln.split()[-1][1:-1] |
| 81 | return _cache_getFullVersion |
| 82 | raise RuntimeError("Cannot find full version??") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 83 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 84 | # The directory we'll use to create the build (will be erased and recreated) |
| 85 | WORKDIR = "/tmp/_py" |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 86 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 87 | # 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] | 88 | # 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] | 89 | DEPSRC = os.path.join(WORKDIR, 'third-party') |
| 90 | DEPSRC = os.path.expanduser('~/Universal/other-sources') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 91 | |
| 92 | # Location of the preferred SDK |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 93 | |
| 94 | ### There are some issues with the SDK selection below here, |
| 95 | ### The resulting binary doesn't work on all platforms that |
| 96 | ### it should. Always default to the 10.4u SDK until that |
| 97 | ### isue is resolved. |
| 98 | ### |
| 99 | ##if int(os.uname()[2].split('.')[0]) == 8: |
| 100 | ## # Explicitly use the 10.4u (universal) SDK when |
| 101 | ## # building on 10.4, the system headers are not |
| 102 | ## # useable for a universal build |
| 103 | ## SDKPATH = "/Developer/SDKs/MacOSX10.4u.sdk" |
| 104 | ##else: |
| 105 | ## SDKPATH = "/" |
| 106 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 107 | SDKPATH = "/Developer/SDKs/MacOSX10.4u.sdk" |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 108 | |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 109 | universal_opts_map = { '32-bit': ('i386', 'ppc',), |
| 110 | '64-bit': ('x86_64', 'ppc64',), |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 111 | 'intel': ('i386', 'x86_64'), |
| 112 | '3-way': ('ppc', 'i386', 'x86_64'), |
| 113 | 'all': ('i386', 'ppc', 'x86_64', 'ppc64',) } |
| 114 | default_target_map = { |
| 115 | '64-bit': '10.5', |
| 116 | '3-way': '10.5', |
| 117 | 'intel': '10.5', |
| 118 | 'all': '10.5', |
| 119 | } |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 120 | |
| 121 | UNIVERSALOPTS = tuple(universal_opts_map.keys()) |
| 122 | |
| 123 | UNIVERSALARCHS = '32-bit' |
| 124 | |
| 125 | ARCHLIST = universal_opts_map[UNIVERSALARCHS] |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 126 | |
Ezio Melotti | 42da663 | 2011-03-15 05:18:48 +0200 | [diff] [blame] | 127 | # Source directory (assume we're in Mac/BuildScript) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 128 | SRCDIR = os.path.dirname( |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 129 | os.path.dirname( |
| 130 | os.path.dirname( |
Thomas Wouters | 73e5a5b | 2006-06-08 15:35:45 +0000 | [diff] [blame] | 131 | os.path.abspath(__file__ |
| 132 | )))) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 133 | |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 134 | # $MACOSX_DEPLOYMENT_TARGET -> minimum OS X level |
| 135 | DEPTARGET = '10.3' |
| 136 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 137 | target_cc_map = { |
| 138 | '10.3': 'gcc-4.0', |
| 139 | '10.4': 'gcc-4.0', |
| 140 | '10.5': 'gcc-4.0', |
| 141 | '10.6': 'gcc-4.2', |
| 142 | } |
| 143 | |
| 144 | CC = target_cc_map[DEPTARGET] |
| 145 | |
| 146 | PYTHON_3 = getVersionTuple() >= (3, 0) |
| 147 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 148 | USAGE = textwrap.dedent("""\ |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 149 | Usage: build_python [options] |
| 150 | |
| 151 | Options: |
| 152 | -? or -h: Show this message |
| 153 | -b DIR |
| 154 | --build-dir=DIR: Create build here (default: %(WORKDIR)r) |
| 155 | --third-party=DIR: Store third-party sources here (default: %(DEPSRC)r) |
| 156 | --sdk-path=DIR: Location of the SDK (default: %(SDKPATH)r) |
| 157 | --src-dir=DIR: Location of the Python sources (default: %(SRCDIR)r) |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 158 | --dep-target=10.n OS X deployment target (default: %(DEPTARGET)r) |
| 159 | --universal-archs=x universal architectures (options: %(UNIVERSALOPTS)r, default: %(UNIVERSALARCHS)r) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 160 | """)% globals() |
| 161 | |
| 162 | |
| 163 | # Instructions for building libraries that are necessary for building a |
| 164 | # batteries included python. |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 165 | # [The recipes are defined here for convenience but instantiated later after |
| 166 | # command line options have been processed.] |
| 167 | def library_recipes(): |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 168 | result = [] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 169 | |
Ned Deily | 4d4c0ee | 2012-04-01 00:17:33 -0700 | [diff] [blame] | 170 | result.extend([ |
| 171 | dict( |
| 172 | name="XZ 5.0.3", |
| 173 | url="http://tukaani.org/xz/xz-5.0.3.tar.gz", |
| 174 | checksum='fefe52f9ecd521de2a8ce38c21a27574', |
| 175 | configure_pre=[ |
| 176 | '--disable-dependency-tracking', |
| 177 | ] |
| 178 | ) |
| 179 | ]) |
| 180 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 181 | if DEPTARGET < '10.5': |
| 182 | result.extend([ |
| 183 | dict( |
Ned Deily | 4f7ff78 | 2011-01-15 05:29:12 +0000 | [diff] [blame] | 184 | name="Bzip2 1.0.6", |
| 185 | url="http://bzip.org/1.0.6/bzip2-1.0.6.tar.gz", |
| 186 | checksum='00b516f4704d4a7cb50a1d97e6e8e15b', |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 187 | configure=None, |
| 188 | install='make install CC=%s PREFIX=%s/usr/local/ CFLAGS="-arch %s -isysroot %s"'%( |
| 189 | CC, |
| 190 | shellQuote(os.path.join(WORKDIR, 'libraries')), |
| 191 | ' -arch '.join(ARCHLIST), |
| 192 | SDKPATH, |
| 193 | ), |
| 194 | ), |
| 195 | dict( |
| 196 | name="ZLib 1.2.3", |
| 197 | url="http://www.gzip.org/zlib/zlib-1.2.3.tar.gz", |
| 198 | checksum='debc62758716a169df9f62e6ab2bc634', |
| 199 | configure=None, |
| 200 | install='make install CC=%s prefix=%s/usr/local/ CFLAGS="-arch %s -isysroot %s"'%( |
| 201 | CC, |
| 202 | shellQuote(os.path.join(WORKDIR, 'libraries')), |
| 203 | ' -arch '.join(ARCHLIST), |
| 204 | SDKPATH, |
| 205 | ), |
| 206 | ), |
| 207 | dict( |
| 208 | # Note that GNU readline is GPL'd software |
Ned Deily | 4f7ff78 | 2011-01-15 05:29:12 +0000 | [diff] [blame] | 209 | name="GNU Readline 6.1.2", |
| 210 | url="http://ftp.gnu.org/pub/gnu/readline/readline-6.1.tar.gz" , |
| 211 | checksum='fc2f7e714fe792db1ce6ddc4c9fb4ef3', |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 212 | patchlevel='0', |
| 213 | patches=[ |
| 214 | # The readline maintainers don't do actual micro releases, but |
| 215 | # just ship a set of patches. |
Ned Deily | 4f7ff78 | 2011-01-15 05:29:12 +0000 | [diff] [blame] | 216 | 'http://ftp.gnu.org/pub/gnu/readline/readline-6.1-patches/readline61-001', |
| 217 | 'http://ftp.gnu.org/pub/gnu/readline/readline-6.1-patches/readline61-002', |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 218 | ] |
| 219 | ), |
| 220 | dict( |
Ned Deily | 4f7ff78 | 2011-01-15 05:29:12 +0000 | [diff] [blame] | 221 | name="SQLite 3.7.4", |
| 222 | url="http://www.sqlite.org/sqlite-autoconf-3070400.tar.gz", |
| 223 | checksum='8f0c690bfb33c3cbbc2471c3d9ba0158', |
| 224 | configure_env=('CFLAGS="-Os' |
| 225 | ' -DSQLITE_ENABLE_FTS3' |
| 226 | ' -DSQLITE_ENABLE_FTS3_PARENTHESIS' |
| 227 | ' -DSQLITE_ENABLE_RTREE' |
| 228 | ' -DSQLITE_TCL=0' |
| 229 | '"'), |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 230 | configure_pre=[ |
| 231 | '--enable-threadsafe', |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 232 | '--enable-shared=no', |
| 233 | '--enable-static=yes', |
Ned Deily | 4f7ff78 | 2011-01-15 05:29:12 +0000 | [diff] [blame] | 234 | '--disable-readline', |
| 235 | '--disable-dependency-tracking', |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 236 | ] |
| 237 | ), |
| 238 | dict( |
| 239 | name="NCurses 5.5", |
| 240 | url="http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.5.tar.gz", |
| 241 | checksum='e73c1ac10b4bfc46db43b2ddfd6244ef', |
| 242 | configure_pre=[ |
Ned Deily | 4f7ff78 | 2011-01-15 05:29:12 +0000 | [diff] [blame] | 243 | "--enable-widec", |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 244 | "--without-cxx", |
| 245 | "--without-ada", |
| 246 | "--without-progs", |
| 247 | "--without-curses-h", |
| 248 | "--enable-shared", |
| 249 | "--with-shared", |
| 250 | "--datadir=/usr/share", |
| 251 | "--sysconfdir=/etc", |
| 252 | "--sharedstatedir=/usr/com", |
| 253 | "--with-terminfo-dirs=/usr/share/terminfo", |
| 254 | "--with-default-terminfo-dir=/usr/share/terminfo", |
| 255 | "--libdir=/Library/Frameworks/Python.framework/Versions/%s/lib"%(getVersion(),), |
| 256 | "--enable-termcap", |
| 257 | ], |
| 258 | patches=[ |
| 259 | "ncurses-5.5.patch", |
| 260 | ], |
| 261 | useLDFlags=False, |
| 262 | install='make && make install DESTDIR=%s && cd %s/usr/local/lib && ln -fs ../../../Library/Frameworks/Python.framework/Versions/%s/lib/lib* .'%( |
| 263 | shellQuote(os.path.join(WORKDIR, 'libraries')), |
| 264 | shellQuote(os.path.join(WORKDIR, 'libraries')), |
| 265 | getVersion(), |
| 266 | ), |
| 267 | ), |
| 268 | ]) |
| 269 | |
Ned Deily | 4f7ff78 | 2011-01-15 05:29:12 +0000 | [diff] [blame] | 270 | if not PYTHON_3: |
| 271 | result.extend([ |
| 272 | dict( |
| 273 | name="Sleepycat DB 4.7.25", |
| 274 | url="http://download.oracle.com/berkeley-db/db-4.7.25.tar.gz", |
| 275 | checksum='ec2b87e833779681a0c3a814aa71359e', |
| 276 | buildDir="build_unix", |
| 277 | configure="../dist/configure", |
| 278 | configure_pre=[ |
| 279 | '--includedir=/usr/local/include/db4', |
| 280 | ] |
| 281 | ), |
| 282 | ]) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 283 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 284 | return result |
| 285 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 286 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 287 | # Instructions for building packages inside the .mpkg. |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 288 | def pkg_recipes(): |
| 289 | unselected_for_python3 = ('selected', 'unselected')[PYTHON_3] |
| 290 | result = [ |
| 291 | dict( |
| 292 | name="PythonFramework", |
| 293 | long_name="Python Framework", |
| 294 | source="/Library/Frameworks/Python.framework", |
| 295 | readme="""\ |
| 296 | This package installs Python.framework, that is the python |
| 297 | interpreter and the standard library. This also includes Python |
| 298 | wrappers for lots of Mac OS X API's. |
| 299 | """, |
| 300 | postflight="scripts/postflight.framework", |
| 301 | selected='selected', |
| 302 | ), |
| 303 | dict( |
| 304 | name="PythonApplications", |
| 305 | long_name="GUI Applications", |
| 306 | source="/Applications/Python %(VER)s", |
| 307 | readme="""\ |
| 308 | This package installs IDLE (an interactive Python IDE), |
| 309 | Python Launcher and Build Applet (create application bundles |
| 310 | from python scripts). |
Thomas Wouters | 73e5a5b | 2006-06-08 15:35:45 +0000 | [diff] [blame] | 311 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 312 | It also installs a number of examples and demos. |
| 313 | """, |
| 314 | required=False, |
| 315 | selected='selected', |
| 316 | ), |
| 317 | dict( |
| 318 | name="PythonUnixTools", |
| 319 | long_name="UNIX command-line tools", |
| 320 | source="/usr/local/bin", |
| 321 | readme="""\ |
| 322 | This package installs the unix tools in /usr/local/bin for |
| 323 | compatibility with older releases of Python. This package |
| 324 | is not necessary to use Python. |
| 325 | """, |
| 326 | required=False, |
| 327 | selected='selected', |
| 328 | ), |
| 329 | dict( |
| 330 | name="PythonDocumentation", |
| 331 | long_name="Python Documentation", |
| 332 | topdir="/Library/Frameworks/Python.framework/Versions/%(VER)s/Resources/English.lproj/Documentation", |
| 333 | source="/pydocs", |
| 334 | readme="""\ |
| 335 | This package installs the python documentation at a location |
| 336 | that is useable for pydoc and IDLE. If you have installed Xcode |
| 337 | it will also install a link to the documentation in |
| 338 | /Developer/Documentation/Python |
| 339 | """, |
| 340 | postflight="scripts/postflight.documentation", |
| 341 | required=False, |
| 342 | selected='selected', |
| 343 | ), |
| 344 | dict( |
| 345 | name="PythonProfileChanges", |
| 346 | long_name="Shell profile updater", |
| 347 | readme="""\ |
| 348 | This packages updates your shell profile to make sure that |
| 349 | the Python tools are found by your shell in preference of |
| 350 | the system provided Python tools. |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 351 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 352 | If you don't install this package you'll have to add |
| 353 | "/Library/Frameworks/Python.framework/Versions/%(VER)s/bin" |
| 354 | to your PATH by hand. |
| 355 | """, |
| 356 | postflight="scripts/postflight.patch-profile", |
| 357 | topdir="/Library/Frameworks/Python.framework", |
| 358 | source="/empty-dir", |
| 359 | required=False, |
| 360 | selected=unselected_for_python3, |
| 361 | ), |
| 362 | ] |
| 363 | |
Ned Deily | 430d7a3 | 2012-06-24 00:19:31 -0700 | [diff] [blame^] | 364 | if DEPTARGET < '10.4' and not PYTHON_3: |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 365 | result.append( |
| 366 | dict( |
| 367 | name="PythonSystemFixes", |
| 368 | long_name="Fix system Python", |
| 369 | readme="""\ |
| 370 | This package updates the system python installation on |
| 371 | Mac OS X 10.3 to ensure that you can build new python extensions |
| 372 | using that copy of python after installing this version. |
| 373 | """, |
| 374 | postflight="../Tools/fixapplepython23.py", |
| 375 | topdir="/Library/Frameworks/Python.framework", |
| 376 | source="/empty-dir", |
| 377 | required=False, |
| 378 | selected=unselected_for_python3, |
| 379 | ) |
| 380 | ) |
| 381 | return result |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 382 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 383 | def fatal(msg): |
| 384 | """ |
| 385 | A fatal error, bail out. |
| 386 | """ |
| 387 | sys.stderr.write('FATAL: ') |
| 388 | sys.stderr.write(msg) |
| 389 | sys.stderr.write('\n') |
| 390 | sys.exit(1) |
| 391 | |
| 392 | def fileContents(fn): |
| 393 | """ |
| 394 | Return the contents of the named file |
| 395 | """ |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 396 | return open(fn, 'r').read() |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 397 | |
| 398 | def runCommand(commandline): |
| 399 | """ |
Ezio Melotti | 1392500 | 2011-03-16 11:05:33 +0200 | [diff] [blame] | 400 | Run a command and raise RuntimeError if it fails. Output is suppressed |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 401 | unless the command fails. |
| 402 | """ |
| 403 | fd = os.popen(commandline, 'r') |
| 404 | data = fd.read() |
| 405 | xit = fd.close() |
Benjamin Peterson | 2a691a8 | 2008-03-31 01:51:45 +0000 | [diff] [blame] | 406 | if xit is not None: |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 407 | sys.stdout.write(data) |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 408 | raise RuntimeError("command failed: %s"%(commandline,)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 409 | |
| 410 | if VERBOSE: |
| 411 | sys.stdout.write(data); sys.stdout.flush() |
| 412 | |
| 413 | def captureCommand(commandline): |
| 414 | fd = os.popen(commandline, 'r') |
| 415 | data = fd.read() |
| 416 | xit = fd.close() |
Benjamin Peterson | 2a691a8 | 2008-03-31 01:51:45 +0000 | [diff] [blame] | 417 | if xit is not None: |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 418 | sys.stdout.write(data) |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 419 | raise RuntimeError("command failed: %s"%(commandline,)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 420 | |
| 421 | return data |
| 422 | |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 423 | def getTclTkVersion(configfile, versionline): |
| 424 | """ |
| 425 | search Tcl or Tk configuration file for version line |
| 426 | """ |
| 427 | try: |
| 428 | f = open(configfile, "r") |
| 429 | except: |
| 430 | fatal("Framework configuration file not found: %s" % configfile) |
| 431 | |
| 432 | for l in f: |
| 433 | if l.startswith(versionline): |
| 434 | f.close() |
| 435 | return l |
| 436 | |
| 437 | fatal("Version variable %s not found in framework configuration file: %s" |
| 438 | % (versionline, configfile)) |
| 439 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 440 | def checkEnvironment(): |
| 441 | """ |
| 442 | Check that we're running on a supported system. |
| 443 | """ |
| 444 | |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 445 | if sys.version_info[0:2] < (2, 4): |
| 446 | fatal("This script must be run with Python 2.4 or later") |
| 447 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 448 | if platform.system() != 'Darwin': |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 449 | fatal("This script should be run on a Mac OS X 10.4 (or later) system") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 450 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 451 | if int(platform.release().split('.')[0]) < 8: |
| 452 | fatal("This script should be run on a Mac OS X 10.4 (or later) system") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 453 | |
| 454 | if not os.path.exists(SDKPATH): |
| 455 | fatal("Please install the latest version of Xcode and the %s SDK"%( |
| 456 | os.path.basename(SDKPATH[:-4]))) |
| 457 | |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 458 | # Because we only support dynamic load of only one major/minor version of |
| 459 | # Tcl/Tk, ensure: |
| 460 | # 1. there are no user-installed frameworks of Tcl/Tk with version |
| 461 | # higher than the Apple-supplied system version |
| 462 | # 2. there is a user-installed framework in /Library/Frameworks with the |
| 463 | # same version as the system version. This allows users to choose |
| 464 | # to install a newer patch level. |
| 465 | |
| 466 | for framework in ['Tcl', 'Tk']: |
Ronald Oussoren | 0499d0b | 2010-12-07 14:41:05 +0000 | [diff] [blame] | 467 | #fw = dict(lower=framework.lower(), |
| 468 | # upper=framework.upper(), |
| 469 | # cap=framework.capitalize()) |
| 470 | #fwpth = "Library/Frameworks/%(cap)s.framework/%(lower)sConfig.sh" % fw |
| 471 | fwpth = 'Library/Frameworks/Tcl.framework/Versions/Current' |
| 472 | sysfw = os.path.join(SDKPATH, 'System', fwpth) |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 473 | libfw = os.path.join('/', fwpth) |
| 474 | usrfw = os.path.join(os.getenv('HOME'), fwpth) |
Ronald Oussoren | 0499d0b | 2010-12-07 14:41:05 +0000 | [diff] [blame] | 475 | #version = "%(upper)s_VERSION" % fw |
| 476 | if os.readlink(libfw) != os.readlink(sysfw): |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 477 | fatal("Version of %s must match %s" % (libfw, sysfw) ) |
| 478 | if os.path.exists(usrfw): |
| 479 | fatal("Please rename %s to avoid possible dynamic load issues." |
| 480 | % usrfw) |
| 481 | |
| 482 | # Remove inherited environment variables which might influence build |
| 483 | environ_var_prefixes = ['CPATH', 'C_INCLUDE_', 'DYLD_', 'LANG', 'LC_', |
| 484 | 'LD_', 'LIBRARY_', 'PATH', 'PYTHON'] |
| 485 | for ev in list(os.environ): |
| 486 | for prefix in environ_var_prefixes: |
| 487 | if ev.startswith(prefix) : |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 488 | print("INFO: deleting environment variable %s=%s" % ( |
| 489 | ev, os.environ[ev])) |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 490 | del os.environ[ev] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 491 | |
Ronald Oussoren | 1e99be7 | 2010-04-20 06:36:47 +0000 | [diff] [blame] | 492 | os.environ['PATH'] = '/bin:/sbin:/usr/bin:/usr/sbin' |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 493 | print("Setting default PATH: %s"%(os.environ['PATH'])) |
Ronald Oussoren | 1e99be7 | 2010-04-20 06:36:47 +0000 | [diff] [blame] | 494 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 495 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 496 | def parseOptions(args=None): |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 497 | """ |
| 498 | Parse arguments and update global settings. |
| 499 | """ |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 500 | global WORKDIR, DEPSRC, SDKPATH, SRCDIR, DEPTARGET |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 501 | global UNIVERSALOPTS, UNIVERSALARCHS, ARCHLIST, CC |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 502 | |
| 503 | if args is None: |
| 504 | args = sys.argv[1:] |
| 505 | |
| 506 | try: |
| 507 | options, args = getopt.getopt(args, '?hb', |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 508 | [ 'build-dir=', 'third-party=', 'sdk-path=' , 'src-dir=', |
| 509 | 'dep-target=', 'universal-archs=', 'help' ]) |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 510 | except getopt.GetoptError: |
| 511 | print(sys.exc_info()[1]) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 512 | sys.exit(1) |
| 513 | |
| 514 | if args: |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 515 | print("Additional arguments") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 516 | sys.exit(1) |
| 517 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 518 | deptarget = None |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 519 | for k, v in options: |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 520 | if k in ('-h', '-?', '--help'): |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 521 | print(USAGE) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 522 | sys.exit(0) |
| 523 | |
| 524 | elif k in ('-d', '--build-dir'): |
| 525 | WORKDIR=v |
| 526 | |
| 527 | elif k in ('--third-party',): |
| 528 | DEPSRC=v |
| 529 | |
| 530 | elif k in ('--sdk-path',): |
| 531 | SDKPATH=v |
| 532 | |
| 533 | elif k in ('--src-dir',): |
| 534 | SRCDIR=v |
| 535 | |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 536 | elif k in ('--dep-target', ): |
| 537 | DEPTARGET=v |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 538 | deptarget=v |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 539 | |
| 540 | elif k in ('--universal-archs', ): |
| 541 | if v in UNIVERSALOPTS: |
| 542 | UNIVERSALARCHS = v |
| 543 | ARCHLIST = universal_opts_map[UNIVERSALARCHS] |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 544 | if deptarget is None: |
| 545 | # Select alternate default deployment |
| 546 | # target |
| 547 | DEPTARGET = default_target_map.get(v, '10.3') |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 548 | else: |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 549 | raise NotImplementedError(v) |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 550 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 551 | else: |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 552 | raise NotImplementedError(k) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 553 | |
| 554 | SRCDIR=os.path.abspath(SRCDIR) |
| 555 | WORKDIR=os.path.abspath(WORKDIR) |
| 556 | SDKPATH=os.path.abspath(SDKPATH) |
| 557 | DEPSRC=os.path.abspath(DEPSRC) |
| 558 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 559 | CC=target_cc_map[DEPTARGET] |
| 560 | |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 561 | print("Settings:") |
| 562 | print(" * Source directory:", SRCDIR) |
| 563 | print(" * Build directory: ", WORKDIR) |
| 564 | print(" * SDK location: ", SDKPATH) |
| 565 | print(" * Third-party source:", DEPSRC) |
| 566 | print(" * Deployment target:", DEPTARGET) |
| 567 | print(" * Universal architectures:", ARCHLIST) |
| 568 | print(" * C compiler:", CC) |
| 569 | print("") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 570 | |
| 571 | |
| 572 | |
| 573 | |
| 574 | def extractArchive(builddir, archiveName): |
| 575 | """ |
| 576 | Extract a source archive into 'builddir'. Returns the path of the |
| 577 | extracted archive. |
| 578 | |
| 579 | XXX: This function assumes that archives contain a toplevel directory |
| 580 | that is has the same name as the basename of the archive. This is |
| 581 | save enough for anything we use. |
| 582 | """ |
| 583 | curdir = os.getcwd() |
| 584 | try: |
| 585 | os.chdir(builddir) |
| 586 | if archiveName.endswith('.tar.gz'): |
| 587 | retval = os.path.basename(archiveName[:-7]) |
| 588 | if os.path.exists(retval): |
| 589 | shutil.rmtree(retval) |
| 590 | fp = os.popen("tar zxf %s 2>&1"%(shellQuote(archiveName),), 'r') |
| 591 | |
| 592 | elif archiveName.endswith('.tar.bz2'): |
| 593 | retval = os.path.basename(archiveName[:-8]) |
| 594 | if os.path.exists(retval): |
| 595 | shutil.rmtree(retval) |
| 596 | fp = os.popen("tar jxf %s 2>&1"%(shellQuote(archiveName),), 'r') |
| 597 | |
| 598 | elif archiveName.endswith('.tar'): |
| 599 | retval = os.path.basename(archiveName[:-4]) |
| 600 | if os.path.exists(retval): |
| 601 | shutil.rmtree(retval) |
| 602 | fp = os.popen("tar xf %s 2>&1"%(shellQuote(archiveName),), 'r') |
| 603 | |
| 604 | elif archiveName.endswith('.zip'): |
| 605 | retval = os.path.basename(archiveName[:-4]) |
| 606 | if os.path.exists(retval): |
| 607 | shutil.rmtree(retval) |
| 608 | fp = os.popen("unzip %s 2>&1"%(shellQuote(archiveName),), 'r') |
| 609 | |
| 610 | data = fp.read() |
| 611 | xit = fp.close() |
| 612 | if xit is not None: |
| 613 | sys.stdout.write(data) |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 614 | raise RuntimeError("Cannot extract %s"%(archiveName,)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 615 | |
| 616 | return os.path.join(builddir, retval) |
| 617 | |
| 618 | finally: |
| 619 | os.chdir(curdir) |
| 620 | |
| 621 | KNOWNSIZES = { |
| 622 | "http://ftp.gnu.org/pub/gnu/readline/readline-5.1.tar.gz": 7952742, |
| 623 | "http://downloads.sleepycat.com/db-4.4.20.tar.gz": 2030276, |
| 624 | } |
| 625 | |
| 626 | def downloadURL(url, fname): |
| 627 | """ |
| 628 | Download the contents of the url into the file. |
| 629 | """ |
| 630 | try: |
| 631 | size = os.path.getsize(fname) |
| 632 | except OSError: |
| 633 | pass |
| 634 | else: |
| 635 | if KNOWNSIZES.get(url) == size: |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 636 | print("Using existing file for", url) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 637 | return |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 638 | fpIn = urllib_request.urlopen(url) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 639 | fpOut = open(fname, 'wb') |
| 640 | block = fpIn.read(10240) |
| 641 | try: |
| 642 | while block: |
| 643 | fpOut.write(block) |
| 644 | block = fpIn.read(10240) |
| 645 | fpIn.close() |
| 646 | fpOut.close() |
| 647 | except: |
| 648 | try: |
| 649 | os.unlink(fname) |
| 650 | except: |
| 651 | pass |
| 652 | |
| 653 | def buildRecipe(recipe, basedir, archList): |
| 654 | """ |
| 655 | Build software using a recipe. This function does the |
| 656 | 'configure;make;make install' dance for C software, with a possibility |
| 657 | to customize this process, basically a poor-mans DarwinPorts. |
| 658 | """ |
| 659 | curdir = os.getcwd() |
| 660 | |
| 661 | name = recipe['name'] |
| 662 | url = recipe['url'] |
| 663 | configure = recipe.get('configure', './configure') |
| 664 | install = recipe.get('install', 'make && make install DESTDIR=%s'%( |
| 665 | shellQuote(basedir))) |
| 666 | |
| 667 | archiveName = os.path.split(url)[-1] |
| 668 | sourceArchive = os.path.join(DEPSRC, archiveName) |
| 669 | |
| 670 | if not os.path.exists(DEPSRC): |
| 671 | os.mkdir(DEPSRC) |
| 672 | |
| 673 | |
| 674 | if os.path.exists(sourceArchive): |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 675 | print("Using local copy of %s"%(name,)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 676 | |
| 677 | else: |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 678 | print("Did not find local copy of %s"%(name,)) |
| 679 | print("Downloading %s"%(name,)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 680 | downloadURL(url, sourceArchive) |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 681 | print("Archive for %s stored as %s"%(name, sourceArchive)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 682 | |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 683 | print("Extracting archive for %s"%(name,)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 684 | buildDir=os.path.join(WORKDIR, '_bld') |
| 685 | if not os.path.exists(buildDir): |
| 686 | os.mkdir(buildDir) |
| 687 | |
| 688 | workDir = extractArchive(buildDir, sourceArchive) |
| 689 | os.chdir(workDir) |
| 690 | if 'buildDir' in recipe: |
| 691 | os.chdir(recipe['buildDir']) |
| 692 | |
| 693 | |
| 694 | for fn in recipe.get('patches', ()): |
| 695 | if fn.startswith('http://'): |
| 696 | # Download the patch before applying it. |
| 697 | path = os.path.join(DEPSRC, os.path.basename(fn)) |
| 698 | downloadURL(fn, path) |
| 699 | fn = path |
| 700 | |
| 701 | fn = os.path.join(curdir, fn) |
| 702 | runCommand('patch -p%s < %s'%(recipe.get('patchlevel', 1), |
| 703 | shellQuote(fn),)) |
| 704 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 705 | if configure is not None: |
| 706 | configure_args = [ |
| 707 | "--prefix=/usr/local", |
| 708 | "--enable-static", |
| 709 | "--disable-shared", |
| 710 | #"CPP=gcc -arch %s -E"%(' -arch '.join(archList,),), |
| 711 | ] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 712 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 713 | if 'configure_pre' in recipe: |
| 714 | args = list(recipe['configure_pre']) |
| 715 | if '--disable-static' in args: |
| 716 | configure_args.remove('--enable-static') |
| 717 | if '--enable-shared' in args: |
| 718 | configure_args.remove('--disable-shared') |
| 719 | configure_args.extend(args) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 720 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 721 | if recipe.get('useLDFlags', 1): |
| 722 | configure_args.extend([ |
| 723 | "CFLAGS=-arch %s -isysroot %s -I%s/usr/local/include"%( |
| 724 | ' -arch '.join(archList), |
| 725 | shellQuote(SDKPATH)[1:-1], |
| 726 | shellQuote(basedir)[1:-1],), |
| 727 | "LDFLAGS=-syslibroot,%s -L%s/usr/local/lib -arch %s"%( |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 728 | shellQuote(SDKPATH)[1:-1], |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 729 | shellQuote(basedir)[1:-1], |
| 730 | ' -arch '.join(archList)), |
| 731 | ]) |
| 732 | else: |
| 733 | configure_args.extend([ |
| 734 | "CFLAGS=-arch %s -isysroot %s -I%s/usr/local/include"%( |
| 735 | ' -arch '.join(archList), |
| 736 | shellQuote(SDKPATH)[1:-1], |
| 737 | shellQuote(basedir)[1:-1],), |
| 738 | ]) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 739 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 740 | if 'configure_post' in recipe: |
| 741 | configure_args = configure_args = list(recipe['configure_post']) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 742 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 743 | configure_args.insert(0, configure) |
| 744 | configure_args = [ shellQuote(a) for a in configure_args ] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 745 | |
Ned Deily | 4f7ff78 | 2011-01-15 05:29:12 +0000 | [diff] [blame] | 746 | if 'configure_env' in recipe: |
| 747 | configure_args.insert(0, recipe['configure_env']) |
| 748 | |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 749 | print("Running configure for %s"%(name,)) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 750 | runCommand(' '.join(configure_args) + ' 2>&1') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 751 | |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 752 | print("Running install for %s"%(name,)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 753 | runCommand('{ ' + install + ' ;} 2>&1') |
| 754 | |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 755 | print("Done %s"%(name,)) |
| 756 | print("") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 757 | |
| 758 | os.chdir(curdir) |
| 759 | |
| 760 | def buildLibraries(): |
| 761 | """ |
| 762 | Build our dependencies into $WORKDIR/libraries/usr/local |
| 763 | """ |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 764 | print("") |
| 765 | print("Building required libraries") |
| 766 | print("") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 767 | universal = os.path.join(WORKDIR, 'libraries') |
| 768 | os.mkdir(universal) |
| 769 | os.makedirs(os.path.join(universal, 'usr', 'local', 'lib')) |
| 770 | os.makedirs(os.path.join(universal, 'usr', 'local', 'include')) |
| 771 | |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 772 | for recipe in library_recipes(): |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 773 | buildRecipe(recipe, universal, ARCHLIST) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 774 | |
| 775 | |
| 776 | |
| 777 | def buildPythonDocs(): |
Ronald Oussoren | 207b4c2 | 2009-03-30 17:20:30 +0000 | [diff] [blame] | 778 | # This stores the documentation as Resources/English.lproj/Documentation |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 779 | # inside the framwork. pydoc and IDLE will pick it up there. |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 780 | print("Install python documentation") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 781 | rootDir = os.path.join(WORKDIR, '_root') |
Ronald Oussoren | 207b4c2 | 2009-03-30 17:20:30 +0000 | [diff] [blame] | 782 | buildDir = os.path.join('../../Doc') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 783 | docdir = os.path.join(rootDir, 'pydocs') |
Ronald Oussoren | 207b4c2 | 2009-03-30 17:20:30 +0000 | [diff] [blame] | 784 | curDir = os.getcwd() |
| 785 | os.chdir(buildDir) |
| 786 | runCommand('make update') |
Martin v. Löwis | 6120ddb | 2010-04-22 13:16:44 +0000 | [diff] [blame] | 787 | runCommand("make html PYTHON='%s'" % os.path.abspath(sys.executable)) |
Ronald Oussoren | 207b4c2 | 2009-03-30 17:20:30 +0000 | [diff] [blame] | 788 | os.chdir(curDir) |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 789 | if not os.path.exists(docdir): |
| 790 | os.mkdir(docdir) |
Ronald Oussoren | f84d7e9 | 2009-05-19 11:27:25 +0000 | [diff] [blame] | 791 | os.rename(os.path.join(buildDir, 'build', 'html'), docdir) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 792 | |
| 793 | |
| 794 | def buildPython(): |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 795 | print("Building a universal python for %s architectures" % UNIVERSALARCHS) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 796 | |
| 797 | buildDir = os.path.join(WORKDIR, '_bld', 'python') |
| 798 | rootDir = os.path.join(WORKDIR, '_root') |
| 799 | |
| 800 | if os.path.exists(buildDir): |
| 801 | shutil.rmtree(buildDir) |
| 802 | if os.path.exists(rootDir): |
| 803 | shutil.rmtree(rootDir) |
Ned Deily | 4f7ff78 | 2011-01-15 05:29:12 +0000 | [diff] [blame] | 804 | os.makedirs(buildDir) |
| 805 | os.makedirs(rootDir) |
| 806 | os.makedirs(os.path.join(rootDir, 'empty-dir')) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 807 | curdir = os.getcwd() |
| 808 | os.chdir(buildDir) |
| 809 | |
| 810 | # Not sure if this is still needed, the original build script |
| 811 | # claims that parts of the install assume python.exe exists. |
| 812 | os.symlink('python', os.path.join(buildDir, 'python.exe')) |
| 813 | |
| 814 | # Extract the version from the configure file, needed to calculate |
| 815 | # several paths. |
| 816 | version = getVersion() |
| 817 | |
Ronald Oussoren | ac4b39f | 2009-03-30 20:05:35 +0000 | [diff] [blame] | 818 | # Since the extra libs are not in their installed framework location |
| 819 | # during the build, augment the library path so that the interpreter |
| 820 | # will find them during its extension import sanity checks. |
| 821 | os.environ['DYLD_LIBRARY_PATH'] = os.path.join(WORKDIR, |
| 822 | 'libraries', 'usr', 'local', 'lib') |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 823 | print("Running configure...") |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 824 | runCommand("%s -C --enable-framework --enable-universalsdk=%s " |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 825 | "--with-universal-archs=%s " |
| 826 | "%s " |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 827 | "LDFLAGS='-g -L%s/libraries/usr/local/lib' " |
| 828 | "OPT='-g -O3 -I%s/libraries/usr/local/include' 2>&1"%( |
| 829 | shellQuote(os.path.join(SRCDIR, 'configure')), shellQuote(SDKPATH), |
| 830 | UNIVERSALARCHS, |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 831 | (' ', '--with-computed-gotos ')[PYTHON_3], |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 832 | shellQuote(WORKDIR)[1:-1], |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 833 | shellQuote(WORKDIR)[1:-1])) |
| 834 | |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 835 | print("Running make") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 836 | runCommand("make") |
| 837 | |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 838 | print("Running make install") |
Ronald Oussoren | f84d7e9 | 2009-05-19 11:27:25 +0000 | [diff] [blame] | 839 | runCommand("make install DESTDIR=%s"%( |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 840 | shellQuote(rootDir))) |
| 841 | |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 842 | print("Running make frameworkinstallextras") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 843 | runCommand("make frameworkinstallextras DESTDIR=%s"%( |
| 844 | shellQuote(rootDir))) |
| 845 | |
Ronald Oussoren | ac4b39f | 2009-03-30 20:05:35 +0000 | [diff] [blame] | 846 | del os.environ['DYLD_LIBRARY_PATH'] |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 847 | print("Copying required shared libraries") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 848 | if os.path.exists(os.path.join(WORKDIR, 'libraries', 'Library')): |
| 849 | runCommand("mv %s/* %s"%( |
| 850 | shellQuote(os.path.join( |
| 851 | WORKDIR, 'libraries', 'Library', 'Frameworks', |
| 852 | 'Python.framework', 'Versions', getVersion(), |
| 853 | 'lib')), |
| 854 | shellQuote(os.path.join(WORKDIR, '_root', 'Library', 'Frameworks', |
| 855 | 'Python.framework', 'Versions', getVersion(), |
| 856 | 'lib')))) |
| 857 | |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 858 | print("Fix file modes") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 859 | frmDir = os.path.join(rootDir, 'Library', 'Frameworks', 'Python.framework') |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 860 | gid = grp.getgrnam('admin').gr_gid |
| 861 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 862 | for dirpath, dirnames, filenames in os.walk(frmDir): |
| 863 | for dn in dirnames: |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 864 | os.chmod(os.path.join(dirpath, dn), STAT_0o775) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 865 | os.chown(os.path.join(dirpath, dn), -1, gid) |
| 866 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 867 | |
| 868 | for fn in filenames: |
| 869 | if os.path.islink(fn): |
| 870 | continue |
| 871 | |
| 872 | # "chmod g+w $fn" |
| 873 | p = os.path.join(dirpath, fn) |
| 874 | st = os.stat(p) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 875 | os.chmod(p, stat.S_IMODE(st.st_mode) | stat.S_IWGRP) |
| 876 | os.chown(p, -1, gid) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 877 | |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 878 | if PYTHON_3: |
| 879 | LDVERSION=None |
| 880 | VERSION=None |
| 881 | ABIFLAGS=None |
Ronald Oussoren | 0499d0b | 2010-12-07 14:41:05 +0000 | [diff] [blame] | 882 | |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 883 | fp = open(os.path.join(buildDir, 'Makefile'), 'r') |
Ronald Oussoren | 0499d0b | 2010-12-07 14:41:05 +0000 | [diff] [blame] | 884 | for ln in fp: |
| 885 | if ln.startswith('VERSION='): |
| 886 | VERSION=ln.split()[1] |
| 887 | if ln.startswith('ABIFLAGS='): |
| 888 | ABIFLAGS=ln.split()[1] |
Ronald Oussoren | 0499d0b | 2010-12-07 14:41:05 +0000 | [diff] [blame] | 889 | if ln.startswith('LDVERSION='): |
| 890 | LDVERSION=ln.split()[1] |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 891 | fp.close() |
Ronald Oussoren | 0499d0b | 2010-12-07 14:41:05 +0000 | [diff] [blame] | 892 | |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 893 | LDVERSION = LDVERSION.replace('$(VERSION)', VERSION) |
| 894 | LDVERSION = LDVERSION.replace('$(ABIFLAGS)', ABIFLAGS) |
| 895 | config_suffix = '-' + LDVERSION |
| 896 | else: |
| 897 | config_suffix = '' # Python 2.x |
Ronald Oussoren | 0499d0b | 2010-12-07 14:41:05 +0000 | [diff] [blame] | 898 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 899 | # We added some directories to the search path during the configure |
| 900 | # phase. Remove those because those directories won't be there on |
| 901 | # the end-users system. |
| 902 | path =os.path.join(rootDir, 'Library', 'Frameworks', 'Python.framework', |
| 903 | 'Versions', version, 'lib', 'python%s'%(version,), |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 904 | 'config' + config_suffix, 'Makefile') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 905 | fp = open(path, 'r') |
| 906 | data = fp.read() |
| 907 | fp.close() |
| 908 | |
| 909 | data = data.replace('-L%s/libraries/usr/local/lib'%(WORKDIR,), '') |
| 910 | data = data.replace('-I%s/libraries/usr/local/include'%(WORKDIR,), '') |
| 911 | fp = open(path, 'w') |
| 912 | fp.write(data) |
| 913 | fp.close() |
| 914 | |
| 915 | # Add symlinks in /usr/local/bin, using relative links |
| 916 | usr_local_bin = os.path.join(rootDir, 'usr', 'local', 'bin') |
| 917 | to_framework = os.path.join('..', '..', '..', 'Library', 'Frameworks', |
| 918 | 'Python.framework', 'Versions', version, 'bin') |
| 919 | if os.path.exists(usr_local_bin): |
| 920 | shutil.rmtree(usr_local_bin) |
| 921 | os.makedirs(usr_local_bin) |
| 922 | for fn in os.listdir( |
| 923 | os.path.join(frmDir, 'Versions', version, 'bin')): |
| 924 | os.symlink(os.path.join(to_framework, fn), |
| 925 | os.path.join(usr_local_bin, fn)) |
| 926 | |
| 927 | os.chdir(curdir) |
| 928 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 929 | if PYTHON_3: |
| 930 | # Remove the 'Current' link, that way we don't accidently mess |
| 931 | # with an already installed version of python 2 |
| 932 | os.unlink(os.path.join(rootDir, 'Library', 'Frameworks', |
| 933 | 'Python.framework', 'Versions', 'Current')) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 934 | |
| 935 | def patchFile(inPath, outPath): |
| 936 | data = fileContents(inPath) |
| 937 | data = data.replace('$FULL_VERSION', getFullVersion()) |
| 938 | data = data.replace('$VERSION', getVersion()) |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 939 | data = data.replace('$MACOSX_DEPLOYMENT_TARGET', ''.join((DEPTARGET, ' or later'))) |
Ronald Oussoren | d010329 | 2010-10-20 12:56:56 +0000 | [diff] [blame] | 940 | data = data.replace('$ARCHITECTURES', ", ".join(universal_opts_map[UNIVERSALARCHS])) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 941 | data = data.replace('$INSTALL_SIZE', installSize()) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 942 | |
| 943 | # This one is not handy as a template variable |
| 944 | data = data.replace('$PYTHONFRAMEWORKINSTALLDIR', '/Library/Frameworks/Python.framework') |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 945 | fp = open(outPath, 'w') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 946 | fp.write(data) |
| 947 | fp.close() |
| 948 | |
| 949 | def patchScript(inPath, outPath): |
| 950 | data = fileContents(inPath) |
| 951 | data = data.replace('@PYVER@', getVersion()) |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 952 | fp = open(outPath, 'w') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 953 | fp.write(data) |
| 954 | fp.close() |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 955 | os.chmod(outPath, STAT_0o755) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 956 | |
| 957 | |
| 958 | |
| 959 | def packageFromRecipe(targetDir, recipe): |
| 960 | curdir = os.getcwd() |
| 961 | try: |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 962 | # The major version (such as 2.5) is included in the package name |
| 963 | # because having two version of python installed at the same time is |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 964 | # common. |
| 965 | pkgname = '%s-%s'%(recipe['name'], getVersion()) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 966 | srcdir = recipe.get('source') |
| 967 | pkgroot = recipe.get('topdir', srcdir) |
| 968 | postflight = recipe.get('postflight') |
| 969 | readme = textwrap.dedent(recipe['readme']) |
| 970 | isRequired = recipe.get('required', True) |
| 971 | |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 972 | print("- building package %s"%(pkgname,)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 973 | |
| 974 | # Substitute some variables |
| 975 | textvars = dict( |
| 976 | VER=getVersion(), |
| 977 | FULLVER=getFullVersion(), |
| 978 | ) |
| 979 | readme = readme % textvars |
| 980 | |
| 981 | if pkgroot is not None: |
| 982 | pkgroot = pkgroot % textvars |
| 983 | else: |
| 984 | pkgroot = '/' |
| 985 | |
| 986 | if srcdir is not None: |
| 987 | srcdir = os.path.join(WORKDIR, '_root', srcdir[1:]) |
| 988 | srcdir = srcdir % textvars |
| 989 | |
| 990 | if postflight is not None: |
| 991 | postflight = os.path.abspath(postflight) |
| 992 | |
| 993 | packageContents = os.path.join(targetDir, pkgname + '.pkg', 'Contents') |
| 994 | os.makedirs(packageContents) |
| 995 | |
| 996 | if srcdir is not None: |
| 997 | os.chdir(srcdir) |
| 998 | runCommand("pax -wf %s . 2>&1"%(shellQuote(os.path.join(packageContents, 'Archive.pax')),)) |
| 999 | runCommand("gzip -9 %s 2>&1"%(shellQuote(os.path.join(packageContents, 'Archive.pax')),)) |
| 1000 | runCommand("mkbom . %s 2>&1"%(shellQuote(os.path.join(packageContents, 'Archive.bom')),)) |
| 1001 | |
| 1002 | fn = os.path.join(packageContents, 'PkgInfo') |
| 1003 | fp = open(fn, 'w') |
| 1004 | fp.write('pmkrpkg1') |
| 1005 | fp.close() |
| 1006 | |
| 1007 | rsrcDir = os.path.join(packageContents, "Resources") |
| 1008 | os.mkdir(rsrcDir) |
| 1009 | fp = open(os.path.join(rsrcDir, 'ReadMe.txt'), 'w') |
| 1010 | fp.write(readme) |
| 1011 | fp.close() |
| 1012 | |
| 1013 | if postflight is not None: |
| 1014 | patchScript(postflight, os.path.join(rsrcDir, 'postflight')) |
| 1015 | |
| 1016 | vers = getFullVersion() |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 1017 | major, minor = getVersionMajorMinor() |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1018 | pl = Plist( |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1019 | CFBundleGetInfoString="Python.%s %s"%(pkgname, vers,), |
| 1020 | CFBundleIdentifier='org.python.Python.%s'%(pkgname,), |
| 1021 | CFBundleName='Python.%s'%(pkgname,), |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1022 | CFBundleShortVersionString=vers, |
| 1023 | IFMajorVersion=major, |
| 1024 | IFMinorVersion=minor, |
| 1025 | IFPkgFormatVersion=0.10000000149011612, |
| 1026 | IFPkgFlagAllowBackRev=False, |
| 1027 | IFPkgFlagAuthorizationAction="RootAuthorization", |
| 1028 | IFPkgFlagDefaultLocation=pkgroot, |
| 1029 | IFPkgFlagFollowLinks=True, |
| 1030 | IFPkgFlagInstallFat=True, |
| 1031 | IFPkgFlagIsRequired=isRequired, |
| 1032 | IFPkgFlagOverwritePermissions=False, |
| 1033 | IFPkgFlagRelocatable=False, |
| 1034 | IFPkgFlagRestartAction="NoRestart", |
| 1035 | IFPkgFlagRootVolumeOnly=True, |
| 1036 | IFPkgFlagUpdateInstalledLangauges=False, |
| 1037 | ) |
| 1038 | writePlist(pl, os.path.join(packageContents, 'Info.plist')) |
| 1039 | |
| 1040 | pl = Plist( |
| 1041 | IFPkgDescriptionDescription=readme, |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1042 | IFPkgDescriptionTitle=recipe.get('long_name', "Python.%s"%(pkgname,)), |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1043 | IFPkgDescriptionVersion=vers, |
| 1044 | ) |
| 1045 | writePlist(pl, os.path.join(packageContents, 'Resources', 'Description.plist')) |
| 1046 | |
| 1047 | finally: |
| 1048 | os.chdir(curdir) |
| 1049 | |
| 1050 | |
| 1051 | def makeMpkgPlist(path): |
| 1052 | |
| 1053 | vers = getFullVersion() |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 1054 | major, minor = getVersionMajorMinor() |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1055 | |
| 1056 | pl = Plist( |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1057 | CFBundleGetInfoString="Python %s"%(vers,), |
| 1058 | CFBundleIdentifier='org.python.Python', |
| 1059 | CFBundleName='Python', |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1060 | CFBundleShortVersionString=vers, |
| 1061 | IFMajorVersion=major, |
| 1062 | IFMinorVersion=minor, |
| 1063 | IFPkgFlagComponentDirectory="Contents/Packages", |
| 1064 | IFPkgFlagPackageList=[ |
| 1065 | dict( |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1066 | IFPkgFlagPackageLocation='%s-%s.pkg'%(item['name'], getVersion()), |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1067 | IFPkgFlagPackageSelection=item.get('selected', 'selected'), |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1068 | ) |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1069 | for item in pkg_recipes() |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1070 | ], |
| 1071 | IFPkgFormatVersion=0.10000000149011612, |
| 1072 | IFPkgFlagBackgroundScaling="proportional", |
| 1073 | IFPkgFlagBackgroundAlignment="left", |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1074 | IFPkgFlagAuthorizationAction="RootAuthorization", |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1075 | ) |
| 1076 | |
| 1077 | writePlist(pl, path) |
| 1078 | |
| 1079 | |
| 1080 | def buildInstaller(): |
| 1081 | |
| 1082 | # Zap all compiled files |
| 1083 | for dirpath, _, filenames in os.walk(os.path.join(WORKDIR, '_root')): |
| 1084 | for fn in filenames: |
| 1085 | if fn.endswith('.pyc') or fn.endswith('.pyo'): |
| 1086 | os.unlink(os.path.join(dirpath, fn)) |
| 1087 | |
| 1088 | outdir = os.path.join(WORKDIR, 'installer') |
| 1089 | if os.path.exists(outdir): |
| 1090 | shutil.rmtree(outdir) |
| 1091 | os.mkdir(outdir) |
| 1092 | |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1093 | pkgroot = os.path.join(outdir, 'Python.mpkg', 'Contents') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1094 | pkgcontents = os.path.join(pkgroot, 'Packages') |
| 1095 | os.makedirs(pkgcontents) |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1096 | for recipe in pkg_recipes(): |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1097 | packageFromRecipe(pkgcontents, recipe) |
| 1098 | |
| 1099 | rsrcDir = os.path.join(pkgroot, 'Resources') |
| 1100 | |
| 1101 | fn = os.path.join(pkgroot, 'PkgInfo') |
| 1102 | fp = open(fn, 'w') |
| 1103 | fp.write('pmkrpkg1') |
| 1104 | fp.close() |
| 1105 | |
| 1106 | os.mkdir(rsrcDir) |
| 1107 | |
| 1108 | makeMpkgPlist(os.path.join(pkgroot, 'Info.plist')) |
| 1109 | pl = Plist( |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1110 | IFPkgDescriptionTitle="Python", |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1111 | IFPkgDescriptionVersion=getVersion(), |
| 1112 | ) |
| 1113 | |
| 1114 | writePlist(pl, os.path.join(pkgroot, 'Resources', 'Description.plist')) |
| 1115 | for fn in os.listdir('resources'): |
| 1116 | if fn == '.svn': continue |
| 1117 | if fn.endswith('.jpg'): |
| 1118 | shutil.copy(os.path.join('resources', fn), os.path.join(rsrcDir, fn)) |
| 1119 | else: |
| 1120 | patchFile(os.path.join('resources', fn), os.path.join(rsrcDir, fn)) |
| 1121 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1122 | shutil.copy("../../LICENSE", os.path.join(rsrcDir, 'License.txt')) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1123 | |
| 1124 | |
| 1125 | def installSize(clear=False, _saved=[]): |
| 1126 | if clear: |
| 1127 | del _saved[:] |
| 1128 | if not _saved: |
| 1129 | data = captureCommand("du -ks %s"%( |
| 1130 | shellQuote(os.path.join(WORKDIR, '_root')))) |
| 1131 | _saved.append("%d"%((0.5 + (int(data.split()[0]) / 1024.0)),)) |
| 1132 | return _saved[0] |
| 1133 | |
| 1134 | |
| 1135 | def buildDMG(): |
| 1136 | """ |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 1137 | Create DMG containing the rootDir. |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1138 | """ |
| 1139 | outdir = os.path.join(WORKDIR, 'diskimage') |
| 1140 | if os.path.exists(outdir): |
| 1141 | shutil.rmtree(outdir) |
| 1142 | |
| 1143 | imagepath = os.path.join(outdir, |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1144 | 'python-%s-macosx%s'%(getFullVersion(),DEPTARGET)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1145 | if INCLUDE_TIMESTAMP: |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1146 | imagepath = imagepath + '-%04d-%02d-%02d'%(time.localtime()[:3]) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1147 | imagepath = imagepath + '.dmg' |
| 1148 | |
| 1149 | os.mkdir(outdir) |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1150 | volname='Python %s'%(getFullVersion()) |
| 1151 | runCommand("hdiutil create -format UDRW -volname %s -srcfolder %s %s"%( |
| 1152 | shellQuote(volname), |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1153 | shellQuote(os.path.join(WORKDIR, 'installer')), |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1154 | shellQuote(imagepath + ".tmp.dmg" ))) |
| 1155 | |
| 1156 | |
| 1157 | if not os.path.exists(os.path.join(WORKDIR, "mnt")): |
| 1158 | os.mkdir(os.path.join(WORKDIR, "mnt")) |
| 1159 | runCommand("hdiutil attach %s -mountroot %s"%( |
| 1160 | shellQuote(imagepath + ".tmp.dmg"), shellQuote(os.path.join(WORKDIR, "mnt")))) |
| 1161 | |
| 1162 | # Custom icon for the DMG, shown when the DMG is mounted. |
| 1163 | shutil.copy("../Icons/Disk Image.icns", |
| 1164 | os.path.join(WORKDIR, "mnt", volname, ".VolumeIcon.icns")) |
| 1165 | runCommand("/Developer/Tools/SetFile -a C %s/"%( |
| 1166 | shellQuote(os.path.join(WORKDIR, "mnt", volname)),)) |
| 1167 | |
| 1168 | runCommand("hdiutil detach %s"%(shellQuote(os.path.join(WORKDIR, "mnt", volname)))) |
| 1169 | |
| 1170 | setIcon(imagepath + ".tmp.dmg", "../Icons/Disk Image.icns") |
| 1171 | runCommand("hdiutil convert %s -format UDZO -o %s"%( |
| 1172 | shellQuote(imagepath + ".tmp.dmg"), shellQuote(imagepath))) |
| 1173 | setIcon(imagepath, "../Icons/Disk Image.icns") |
| 1174 | |
| 1175 | os.unlink(imagepath + ".tmp.dmg") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1176 | |
| 1177 | return imagepath |
| 1178 | |
| 1179 | |
| 1180 | def setIcon(filePath, icnsPath): |
| 1181 | """ |
| 1182 | Set the custom icon for the specified file or directory. |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1183 | """ |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1184 | |
Ronald Oussoren | 7005067 | 2010-04-30 15:00:26 +0000 | [diff] [blame] | 1185 | dirPath = os.path.normpath(os.path.dirname(__file__)) |
| 1186 | toolPath = os.path.join(dirPath, "seticon.app/Contents/MacOS/seticon") |
Ronald Oussoren | 207b4c2 | 2009-03-30 17:20:30 +0000 | [diff] [blame] | 1187 | if not os.path.exists(toolPath) or os.stat(toolPath).st_mtime < os.stat(dirPath + '/seticon.m').st_mtime: |
| 1188 | # NOTE: The tool is created inside an .app bundle, otherwise it won't work due |
| 1189 | # to connections to the window server. |
Ronald Oussoren | 7005067 | 2010-04-30 15:00:26 +0000 | [diff] [blame] | 1190 | appPath = os.path.join(dirPath, "seticon.app/Contents/MacOS") |
| 1191 | if not os.path.exists(appPath): |
| 1192 | os.makedirs(appPath) |
Ronald Oussoren | 207b4c2 | 2009-03-30 17:20:30 +0000 | [diff] [blame] | 1193 | runCommand("cc -o %s %s/seticon.m -framework Cocoa"%( |
| 1194 | shellQuote(toolPath), shellQuote(dirPath))) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1195 | |
Ronald Oussoren | 207b4c2 | 2009-03-30 17:20:30 +0000 | [diff] [blame] | 1196 | runCommand("%s %s %s"%(shellQuote(os.path.abspath(toolPath)), shellQuote(icnsPath), |
| 1197 | shellQuote(filePath))) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1198 | |
| 1199 | def main(): |
| 1200 | # First parse options and check if we can perform our work |
| 1201 | parseOptions() |
| 1202 | checkEnvironment() |
| 1203 | |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1204 | os.environ['MACOSX_DEPLOYMENT_TARGET'] = DEPTARGET |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1205 | os.environ['CC'] = CC |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1206 | |
| 1207 | if os.path.exists(WORKDIR): |
| 1208 | shutil.rmtree(WORKDIR) |
| 1209 | os.mkdir(WORKDIR) |
| 1210 | |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 1211 | os.environ['LC_ALL'] = 'C' |
| 1212 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1213 | # Then build third-party libraries such as sleepycat DB4. |
| 1214 | buildLibraries() |
| 1215 | |
| 1216 | # Now build python itself |
| 1217 | buildPython() |
Ronald Oussoren | 6bf6367 | 2009-03-31 13:25:17 +0000 | [diff] [blame] | 1218 | |
| 1219 | # And then build the documentation |
| 1220 | # Remove the Deployment Target from the shell |
| 1221 | # environment, it's no longer needed and |
| 1222 | # an unexpected build target can cause problems |
| 1223 | # when Sphinx and its dependencies need to |
| 1224 | # be (re-)installed. |
| 1225 | del os.environ['MACOSX_DEPLOYMENT_TARGET'] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1226 | buildPythonDocs() |
Ronald Oussoren | 6bf6367 | 2009-03-31 13:25:17 +0000 | [diff] [blame] | 1227 | |
| 1228 | |
| 1229 | # Prepare the applications folder |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1230 | fn = os.path.join(WORKDIR, "_root", "Applications", |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 1231 | "Python %s"%(getVersion(),), "Update Shell Profile.command") |
Ronald Oussoren | bc44866 | 2009-02-12 16:08:14 +0000 | [diff] [blame] | 1232 | patchScript("scripts/postflight.patch-profile", fn) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1233 | |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 1234 | folder = os.path.join(WORKDIR, "_root", "Applications", "Python %s"%( |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1235 | getVersion(),)) |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 1236 | os.chmod(folder, STAT_0o755) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1237 | setIcon(folder, "../Icons/Python Folder.icns") |
| 1238 | |
| 1239 | # Create the installer |
| 1240 | buildInstaller() |
| 1241 | |
| 1242 | # And copy the readme into the directory containing the installer |
| 1243 | patchFile('resources/ReadMe.txt', os.path.join(WORKDIR, 'installer', 'ReadMe.txt')) |
| 1244 | |
| 1245 | # Ditto for the license file. |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1246 | shutil.copy('../../LICENSE', os.path.join(WORKDIR, 'installer', 'License.txt')) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1247 | |
| 1248 | fp = open(os.path.join(WORKDIR, 'installer', 'Build.txt'), 'w') |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 1249 | fp.write("# BUILD INFO\n") |
| 1250 | fp.write("# Date: %s\n" % time.ctime()) |
| 1251 | fp.write("# By: %s\n" % pwd.getpwuid(os.getuid()).pw_gecos) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1252 | fp.close() |
| 1253 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1254 | # And copy it to a DMG |
| 1255 | buildDMG() |
| 1256 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1257 | if __name__ == "__main__": |
| 1258 | main() |