Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1 | #!/usr/bin/python2.3 |
| 2 | """ |
| 3 | This script is used to build the "official unofficial" universal build on |
| 4 | Mac OS X. It requires Mac OS X 10.4, Xcode 2.2 and the 10.4u SDK to do its |
| 5 | work. |
| 6 | |
| 7 | Please ensure that this script keeps working with Python 2.3, to avoid |
| 8 | bootstrap issues (/usr/bin/python is Python 2.3 on OSX 10.4) |
| 9 | |
| 10 | Usage: see USAGE variable in the script. |
| 11 | """ |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 12 | import platform, os, sys, getopt, textwrap, shutil, urllib2, stat, time, pwd |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 13 | import grp |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 14 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 15 | INCLUDE_TIMESTAMP = 1 |
| 16 | VERBOSE = 1 |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 17 | |
| 18 | from plistlib import Plist |
| 19 | |
| 20 | import MacOS |
| 21 | import Carbon.File |
| 22 | import Carbon.Icn |
| 23 | import Carbon.Res |
| 24 | from Carbon.Files import kCustomIconResource, fsRdWrPerm, kHasCustomIcon |
| 25 | from Carbon.Files import kFSCatInfoFinderInfo |
| 26 | |
| 27 | try: |
| 28 | from plistlib import writePlist |
| 29 | except ImportError: |
| 30 | # We're run using python2.3 |
| 31 | def writePlist(plist, path): |
| 32 | plist.write(path) |
| 33 | |
| 34 | def shellQuote(value): |
| 35 | """ |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 36 | 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] | 37 | a shell command. |
| 38 | """ |
| 39 | return "'%s'"%(value.replace("'", "'\"'\"'")) |
| 40 | |
| 41 | def grepValue(fn, variable): |
| 42 | variable = variable + '=' |
| 43 | for ln in open(fn, 'r'): |
| 44 | if ln.startswith(variable): |
| 45 | value = ln[len(variable):].strip() |
| 46 | return value[1:-1] |
| 47 | |
| 48 | def getVersion(): |
| 49 | return grepValue(os.path.join(SRCDIR, 'configure'), 'PACKAGE_VERSION') |
| 50 | |
| 51 | def getFullVersion(): |
| 52 | fn = os.path.join(SRCDIR, 'Include', 'patchlevel.h') |
| 53 | for ln in open(fn): |
| 54 | if 'PY_VERSION' in ln: |
| 55 | return ln.split()[-1][1:-1] |
| 56 | |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 57 | raise RuntimeError, "Cannot find full version??" |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 58 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 59 | # The directory we'll use to create the build (will be erased and recreated) |
| 60 | WORKDIR = "/tmp/_py" |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 61 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 62 | # 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] | 63 | # 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] | 64 | DEPSRC = os.path.join(WORKDIR, 'third-party') |
| 65 | DEPSRC = os.path.expanduser('~/Universal/other-sources') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 66 | |
| 67 | # Location of the preferred SDK |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 68 | SDKPATH = "/Developer/SDKs/MacOSX10.4u.sdk" |
| 69 | #SDKPATH = "/" |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 70 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 71 | ARCHLIST = ('i386', 'ppc',) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 72 | |
Thomas Wouters | 73e5a5b | 2006-06-08 15:35:45 +0000 | [diff] [blame] | 73 | # Source directory (asume we're in Mac/BuildScript) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 74 | SRCDIR = os.path.dirname( |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 75 | os.path.dirname( |
| 76 | os.path.dirname( |
Thomas Wouters | 73e5a5b | 2006-06-08 15:35:45 +0000 | [diff] [blame] | 77 | os.path.abspath(__file__ |
| 78 | )))) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 79 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 80 | USAGE = textwrap.dedent("""\ |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 81 | Usage: build_python [options] |
| 82 | |
| 83 | Options: |
| 84 | -? or -h: Show this message |
| 85 | -b DIR |
| 86 | --build-dir=DIR: Create build here (default: %(WORKDIR)r) |
| 87 | --third-party=DIR: Store third-party sources here (default: %(DEPSRC)r) |
| 88 | --sdk-path=DIR: Location of the SDK (default: %(SDKPATH)r) |
| 89 | --src-dir=DIR: Location of the Python sources (default: %(SRCDIR)r) |
| 90 | """)% globals() |
| 91 | |
| 92 | |
| 93 | # Instructions for building libraries that are necessary for building a |
| 94 | # batteries included python. |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 95 | LIBRARY_RECIPES = [ |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 96 | dict( |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 97 | name="Bzip2 1.0.3", |
| 98 | url="http://www.bzip.org/1.0.3/bzip2-1.0.3.tar.gz", |
| 99 | configure=None, |
| 100 | install='make install PREFIX=%s/usr/local/ CFLAGS="-arch %s -isysroot %s"'%( |
| 101 | shellQuote(os.path.join(WORKDIR, 'libraries')), |
| 102 | ' -arch '.join(ARCHLIST), |
| 103 | SDKPATH, |
| 104 | ), |
| 105 | ), |
| 106 | dict( |
| 107 | name="ZLib 1.2.3", |
| 108 | url="http://www.gzip.org/zlib/zlib-1.2.3.tar.gz", |
| 109 | configure=None, |
| 110 | install='make install prefix=%s/usr/local/ CFLAGS="-arch %s -isysroot %s"'%( |
| 111 | shellQuote(os.path.join(WORKDIR, 'libraries')), |
| 112 | ' -arch '.join(ARCHLIST), |
| 113 | SDKPATH, |
| 114 | ), |
| 115 | ), |
| 116 | dict( |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 117 | # Note that GNU readline is GPL'd software |
| 118 | name="GNU Readline 5.1.4", |
| 119 | url="http://ftp.gnu.org/pub/gnu/readline/readline-5.1.tar.gz" , |
| 120 | patchlevel='0', |
| 121 | patches=[ |
| 122 | # The readline maintainers don't do actual micro releases, but |
| 123 | # just ship a set of patches. |
| 124 | 'http://ftp.gnu.org/pub/gnu/readline/readline-5.1-patches/readline51-001', |
| 125 | 'http://ftp.gnu.org/pub/gnu/readline/readline-5.1-patches/readline51-002', |
| 126 | 'http://ftp.gnu.org/pub/gnu/readline/readline-5.1-patches/readline51-003', |
| 127 | 'http://ftp.gnu.org/pub/gnu/readline/readline-5.1-patches/readline51-004', |
| 128 | ] |
| 129 | ), |
| 130 | |
| 131 | dict( |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 132 | name="SQLite 3.6.3", |
| 133 | url="http://www.sqlite.org/sqlite-3.6.3.tar.gz", |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 134 | checksum='93f742986e8bc2dfa34792e16df017a6feccf3a2', |
| 135 | configure_pre=[ |
| 136 | '--enable-threadsafe', |
| 137 | '--enable-tempstore', |
| 138 | '--enable-shared=no', |
| 139 | '--enable-static=yes', |
| 140 | '--disable-tcl', |
| 141 | ] |
| 142 | ), |
| 143 | |
| 144 | dict( |
| 145 | name="NCurses 5.5", |
| 146 | url="http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.5.tar.gz", |
| 147 | configure_pre=[ |
| 148 | "--without-cxx", |
| 149 | "--without-ada", |
| 150 | "--without-progs", |
| 151 | "--without-curses-h", |
| 152 | "--enable-shared", |
| 153 | "--with-shared", |
| 154 | "--datadir=/usr/share", |
| 155 | "--sysconfdir=/etc", |
| 156 | "--sharedstatedir=/usr/com", |
| 157 | "--with-terminfo-dirs=/usr/share/terminfo", |
| 158 | "--with-default-terminfo-dir=/usr/share/terminfo", |
| 159 | "--libdir=/Library/Frameworks/Python.framework/Versions/%s/lib"%(getVersion(),), |
| 160 | "--enable-termcap", |
| 161 | ], |
| 162 | patches=[ |
| 163 | "ncurses-5.5.patch", |
| 164 | ], |
| 165 | useLDFlags=False, |
| 166 | install='make && make install DESTDIR=%s && cd %s/usr/local/lib && ln -fs ../../../Library/Frameworks/Python.framework/Versions/%s/lib/lib* .'%( |
| 167 | shellQuote(os.path.join(WORKDIR, 'libraries')), |
| 168 | shellQuote(os.path.join(WORKDIR, 'libraries')), |
| 169 | getVersion(), |
| 170 | ), |
| 171 | ), |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 172 | ] |
| 173 | |
| 174 | |
| 175 | # Instructions for building packages inside the .mpkg. |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 176 | PKG_RECIPES = [ |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 177 | dict( |
| 178 | name="PythonFramework", |
| 179 | long_name="Python Framework", |
| 180 | source="/Library/Frameworks/Python.framework", |
| 181 | readme="""\ |
| 182 | This package installs Python.framework, that is the python |
| 183 | interpreter and the standard library. This also includes Python |
| 184 | wrappers for lots of Mac OS X API's. |
| 185 | """, |
| 186 | postflight="scripts/postflight.framework", |
Ronald Oussoren | 360e98c | 2008-12-30 14:16:51 +0000 | [diff] [blame] | 187 | selected='selected', |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 188 | ), |
| 189 | dict( |
| 190 | name="PythonApplications", |
| 191 | long_name="GUI Applications", |
Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 192 | source="/Applications/Python %(VER)s", |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 193 | readme="""\ |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 194 | This package installs IDLE (an interactive Python IDE), |
Thomas Wouters | 73e5a5b | 2006-06-08 15:35:45 +0000 | [diff] [blame] | 195 | Python Launcher and Build Applet (create application bundles |
| 196 | from python scripts). |
| 197 | |
| 198 | It also installs a number of examples and demos. |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 199 | """, |
| 200 | required=False, |
Ronald Oussoren | 360e98c | 2008-12-30 14:16:51 +0000 | [diff] [blame] | 201 | selected='selected', |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 202 | ), |
| 203 | dict( |
| 204 | name="PythonUnixTools", |
| 205 | long_name="UNIX command-line tools", |
| 206 | source="/usr/local/bin", |
| 207 | readme="""\ |
| 208 | This package installs the unix tools in /usr/local/bin for |
| 209 | compatibility with older releases of MacPython. This package |
| 210 | is not necessary to use MacPython. |
| 211 | """, |
| 212 | required=False, |
Ronald Oussoren | 360e98c | 2008-12-30 14:16:51 +0000 | [diff] [blame] | 213 | selected='unselected', |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 214 | ), |
| 215 | dict( |
| 216 | name="PythonDocumentation", |
| 217 | long_name="Python Documentation", |
| 218 | topdir="/Library/Frameworks/Python.framework/Versions/%(VER)s/Resources/English.lproj/Documentation", |
| 219 | source="/pydocs", |
| 220 | readme="""\ |
| 221 | This package installs the python documentation at a location |
| 222 | that is useable for pydoc and IDLE. If you have installed Xcode |
| 223 | it will also install a link to the documentation in |
| 224 | /Developer/Documentation/Python |
| 225 | """, |
| 226 | postflight="scripts/postflight.documentation", |
| 227 | required=False, |
Ronald Oussoren | 360e98c | 2008-12-30 14:16:51 +0000 | [diff] [blame] | 228 | selected='selected', |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 229 | ), |
| 230 | dict( |
| 231 | name="PythonProfileChanges", |
| 232 | long_name="Shell profile updater", |
| 233 | readme="""\ |
| 234 | This packages updates your shell profile to make sure that |
| 235 | the MacPython tools are found by your shell in preference of |
| 236 | the system provided Python tools. |
| 237 | |
| 238 | If you don't install this package you'll have to add |
| 239 | "/Library/Frameworks/Python.framework/Versions/%(VER)s/bin" |
| 240 | to your PATH by hand. |
| 241 | """, |
| 242 | postflight="scripts/postflight.patch-profile", |
| 243 | topdir="/Library/Frameworks/Python.framework", |
| 244 | source="/empty-dir", |
| 245 | required=False, |
Ronald Oussoren | 360e98c | 2008-12-30 14:16:51 +0000 | [diff] [blame] | 246 | selected='unselected', |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 247 | ), |
Thomas Wouters | 73e5a5b | 2006-06-08 15:35:45 +0000 | [diff] [blame] | 248 | dict( |
| 249 | name="PythonSystemFixes", |
| 250 | long_name="Fix system Python", |
| 251 | readme="""\ |
| 252 | This package updates the system python installation on |
| 253 | Mac OS X 10.3 to ensure that you can build new python extensions |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 254 | using that copy of python after installing this version. |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 255 | """, |
Thomas Wouters | 73e5a5b | 2006-06-08 15:35:45 +0000 | [diff] [blame] | 256 | postflight="../Tools/fixapplepython23.py", |
| 257 | topdir="/Library/Frameworks/Python.framework", |
| 258 | source="/empty-dir", |
| 259 | required=False, |
Ronald Oussoren | 360e98c | 2008-12-30 14:16:51 +0000 | [diff] [blame] | 260 | selected='unselected', |
Thomas Wouters | 73e5a5b | 2006-06-08 15:35:45 +0000 | [diff] [blame] | 261 | ) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 262 | ] |
| 263 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 264 | def fatal(msg): |
| 265 | """ |
| 266 | A fatal error, bail out. |
| 267 | """ |
| 268 | sys.stderr.write('FATAL: ') |
| 269 | sys.stderr.write(msg) |
| 270 | sys.stderr.write('\n') |
| 271 | sys.exit(1) |
| 272 | |
| 273 | def fileContents(fn): |
| 274 | """ |
| 275 | Return the contents of the named file |
| 276 | """ |
| 277 | return open(fn, 'rb').read() |
| 278 | |
| 279 | def runCommand(commandline): |
| 280 | """ |
| 281 | Run a command and raise RuntimeError if it fails. Output is surpressed |
| 282 | unless the command fails. |
| 283 | """ |
| 284 | fd = os.popen(commandline, 'r') |
| 285 | data = fd.read() |
| 286 | xit = fd.close() |
Benjamin Peterson | 2a691a8 | 2008-03-31 01:51:45 +0000 | [diff] [blame] | 287 | if xit is not None: |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 288 | sys.stdout.write(data) |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 289 | raise RuntimeError, "command failed: %s"%(commandline,) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 290 | |
| 291 | if VERBOSE: |
| 292 | sys.stdout.write(data); sys.stdout.flush() |
| 293 | |
| 294 | def captureCommand(commandline): |
| 295 | fd = os.popen(commandline, 'r') |
| 296 | data = fd.read() |
| 297 | xit = fd.close() |
Benjamin Peterson | 2a691a8 | 2008-03-31 01:51:45 +0000 | [diff] [blame] | 298 | if xit is not None: |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 299 | sys.stdout.write(data) |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 300 | raise RuntimeError, "command failed: %s"%(commandline,) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 301 | |
| 302 | return data |
| 303 | |
| 304 | def checkEnvironment(): |
| 305 | """ |
| 306 | Check that we're running on a supported system. |
| 307 | """ |
| 308 | |
| 309 | if platform.system() != 'Darwin': |
| 310 | fatal("This script should be run on a Mac OS X 10.4 system") |
| 311 | |
| 312 | if platform.release() <= '8.': |
| 313 | fatal("This script should be run on a Mac OS X 10.4 system") |
| 314 | |
| 315 | if not os.path.exists(SDKPATH): |
| 316 | fatal("Please install the latest version of Xcode and the %s SDK"%( |
| 317 | os.path.basename(SDKPATH[:-4]))) |
| 318 | |
| 319 | |
| 320 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 321 | def parseOptions(args=None): |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 322 | """ |
| 323 | Parse arguments and update global settings. |
| 324 | """ |
| 325 | global WORKDIR, DEPSRC, SDKPATH, SRCDIR |
| 326 | |
| 327 | if args is None: |
| 328 | args = sys.argv[1:] |
| 329 | |
| 330 | try: |
| 331 | options, args = getopt.getopt(args, '?hb', |
| 332 | [ 'build-dir=', 'third-party=', 'sdk-path=' , 'src-dir=']) |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 333 | except getopt.error, msg: |
| 334 | print msg |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 335 | sys.exit(1) |
| 336 | |
| 337 | if args: |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 338 | print "Additional arguments" |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 339 | sys.exit(1) |
| 340 | |
| 341 | for k, v in options: |
| 342 | if k in ('-h', '-?'): |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 343 | print USAGE |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 344 | sys.exit(0) |
| 345 | |
| 346 | elif k in ('-d', '--build-dir'): |
| 347 | WORKDIR=v |
| 348 | |
| 349 | elif k in ('--third-party',): |
| 350 | DEPSRC=v |
| 351 | |
| 352 | elif k in ('--sdk-path',): |
| 353 | SDKPATH=v |
| 354 | |
| 355 | elif k in ('--src-dir',): |
| 356 | SRCDIR=v |
| 357 | |
| 358 | else: |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 359 | raise NotImplementedError, k |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 360 | |
| 361 | SRCDIR=os.path.abspath(SRCDIR) |
| 362 | WORKDIR=os.path.abspath(WORKDIR) |
| 363 | SDKPATH=os.path.abspath(SDKPATH) |
| 364 | DEPSRC=os.path.abspath(DEPSRC) |
| 365 | |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 366 | print "Settings:" |
| 367 | print " * Source directory:", SRCDIR |
| 368 | print " * Build directory: ", WORKDIR |
| 369 | print " * SDK location: ", SDKPATH |
| 370 | print " * third-party source:", DEPSRC |
| 371 | print "" |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | def extractArchive(builddir, archiveName): |
| 377 | """ |
| 378 | Extract a source archive into 'builddir'. Returns the path of the |
| 379 | extracted archive. |
| 380 | |
| 381 | XXX: This function assumes that archives contain a toplevel directory |
| 382 | that is has the same name as the basename of the archive. This is |
| 383 | save enough for anything we use. |
| 384 | """ |
| 385 | curdir = os.getcwd() |
| 386 | try: |
| 387 | os.chdir(builddir) |
| 388 | if archiveName.endswith('.tar.gz'): |
| 389 | retval = os.path.basename(archiveName[:-7]) |
| 390 | if os.path.exists(retval): |
| 391 | shutil.rmtree(retval) |
| 392 | fp = os.popen("tar zxf %s 2>&1"%(shellQuote(archiveName),), 'r') |
| 393 | |
| 394 | elif archiveName.endswith('.tar.bz2'): |
| 395 | retval = os.path.basename(archiveName[:-8]) |
| 396 | if os.path.exists(retval): |
| 397 | shutil.rmtree(retval) |
| 398 | fp = os.popen("tar jxf %s 2>&1"%(shellQuote(archiveName),), 'r') |
| 399 | |
| 400 | elif archiveName.endswith('.tar'): |
| 401 | retval = os.path.basename(archiveName[:-4]) |
| 402 | if os.path.exists(retval): |
| 403 | shutil.rmtree(retval) |
| 404 | fp = os.popen("tar xf %s 2>&1"%(shellQuote(archiveName),), 'r') |
| 405 | |
| 406 | elif archiveName.endswith('.zip'): |
| 407 | retval = os.path.basename(archiveName[:-4]) |
| 408 | if os.path.exists(retval): |
| 409 | shutil.rmtree(retval) |
| 410 | fp = os.popen("unzip %s 2>&1"%(shellQuote(archiveName),), 'r') |
| 411 | |
| 412 | data = fp.read() |
| 413 | xit = fp.close() |
| 414 | if xit is not None: |
| 415 | sys.stdout.write(data) |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 416 | raise RuntimeError, "Cannot extract %s"%(archiveName,) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 417 | |
| 418 | return os.path.join(builddir, retval) |
| 419 | |
| 420 | finally: |
| 421 | os.chdir(curdir) |
| 422 | |
| 423 | KNOWNSIZES = { |
| 424 | "http://ftp.gnu.org/pub/gnu/readline/readline-5.1.tar.gz": 7952742, |
| 425 | "http://downloads.sleepycat.com/db-4.4.20.tar.gz": 2030276, |
| 426 | } |
| 427 | |
| 428 | def downloadURL(url, fname): |
| 429 | """ |
| 430 | Download the contents of the url into the file. |
| 431 | """ |
| 432 | try: |
| 433 | size = os.path.getsize(fname) |
| 434 | except OSError: |
| 435 | pass |
| 436 | else: |
| 437 | if KNOWNSIZES.get(url) == size: |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 438 | print "Using existing file for", url |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 439 | return |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 440 | fpIn = urllib2.urlopen(url) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 441 | fpOut = open(fname, 'wb') |
| 442 | block = fpIn.read(10240) |
| 443 | try: |
| 444 | while block: |
| 445 | fpOut.write(block) |
| 446 | block = fpIn.read(10240) |
| 447 | fpIn.close() |
| 448 | fpOut.close() |
| 449 | except: |
| 450 | try: |
| 451 | os.unlink(fname) |
| 452 | except: |
| 453 | pass |
| 454 | |
| 455 | def buildRecipe(recipe, basedir, archList): |
| 456 | """ |
| 457 | Build software using a recipe. This function does the |
| 458 | 'configure;make;make install' dance for C software, with a possibility |
| 459 | to customize this process, basically a poor-mans DarwinPorts. |
| 460 | """ |
| 461 | curdir = os.getcwd() |
| 462 | |
| 463 | name = recipe['name'] |
| 464 | url = recipe['url'] |
| 465 | configure = recipe.get('configure', './configure') |
| 466 | install = recipe.get('install', 'make && make install DESTDIR=%s'%( |
| 467 | shellQuote(basedir))) |
| 468 | |
| 469 | archiveName = os.path.split(url)[-1] |
| 470 | sourceArchive = os.path.join(DEPSRC, archiveName) |
| 471 | |
| 472 | if not os.path.exists(DEPSRC): |
| 473 | os.mkdir(DEPSRC) |
| 474 | |
| 475 | |
| 476 | if os.path.exists(sourceArchive): |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 477 | print "Using local copy of %s"%(name,) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 478 | |
| 479 | else: |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 480 | print "Downloading %s"%(name,) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 481 | downloadURL(url, sourceArchive) |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 482 | print "Archive for %s stored as %s"%(name, sourceArchive) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 483 | |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 484 | print "Extracting archive for %s"%(name,) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 485 | buildDir=os.path.join(WORKDIR, '_bld') |
| 486 | if not os.path.exists(buildDir): |
| 487 | os.mkdir(buildDir) |
| 488 | |
| 489 | workDir = extractArchive(buildDir, sourceArchive) |
| 490 | os.chdir(workDir) |
| 491 | if 'buildDir' in recipe: |
| 492 | os.chdir(recipe['buildDir']) |
| 493 | |
| 494 | |
| 495 | for fn in recipe.get('patches', ()): |
| 496 | if fn.startswith('http://'): |
| 497 | # Download the patch before applying it. |
| 498 | path = os.path.join(DEPSRC, os.path.basename(fn)) |
| 499 | downloadURL(fn, path) |
| 500 | fn = path |
| 501 | |
| 502 | fn = os.path.join(curdir, fn) |
| 503 | runCommand('patch -p%s < %s'%(recipe.get('patchlevel', 1), |
| 504 | shellQuote(fn),)) |
| 505 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 506 | if configure is not None: |
| 507 | configure_args = [ |
| 508 | "--prefix=/usr/local", |
| 509 | "--enable-static", |
| 510 | "--disable-shared", |
| 511 | #"CPP=gcc -arch %s -E"%(' -arch '.join(archList,),), |
| 512 | ] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 513 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 514 | if 'configure_pre' in recipe: |
| 515 | args = list(recipe['configure_pre']) |
| 516 | if '--disable-static' in args: |
| 517 | configure_args.remove('--enable-static') |
| 518 | if '--enable-shared' in args: |
| 519 | configure_args.remove('--disable-shared') |
| 520 | configure_args.extend(args) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 521 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 522 | if recipe.get('useLDFlags', 1): |
| 523 | configure_args.extend([ |
| 524 | "CFLAGS=-arch %s -isysroot %s -I%s/usr/local/include"%( |
| 525 | ' -arch '.join(archList), |
| 526 | shellQuote(SDKPATH)[1:-1], |
| 527 | shellQuote(basedir)[1:-1],), |
| 528 | "LDFLAGS=-syslibroot,%s -L%s/usr/local/lib -arch %s"%( |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 529 | shellQuote(SDKPATH)[1:-1], |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 530 | shellQuote(basedir)[1:-1], |
| 531 | ' -arch '.join(archList)), |
| 532 | ]) |
| 533 | else: |
| 534 | configure_args.extend([ |
| 535 | "CFLAGS=-arch %s -isysroot %s -I%s/usr/local/include"%( |
| 536 | ' -arch '.join(archList), |
| 537 | shellQuote(SDKPATH)[1:-1], |
| 538 | shellQuote(basedir)[1:-1],), |
| 539 | ]) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 540 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 541 | if 'configure_post' in recipe: |
| 542 | configure_args = configure_args = list(recipe['configure_post']) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 543 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 544 | configure_args.insert(0, configure) |
| 545 | configure_args = [ shellQuote(a) for a in configure_args ] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 546 | |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 547 | print "Running configure for %s"%(name,) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 548 | runCommand(' '.join(configure_args) + ' 2>&1') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 549 | |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 550 | print "Running install for %s"%(name,) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 551 | runCommand('{ ' + install + ' ;} 2>&1') |
| 552 | |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 553 | print "Done %s"%(name,) |
| 554 | print "" |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 555 | |
| 556 | os.chdir(curdir) |
| 557 | |
| 558 | def buildLibraries(): |
| 559 | """ |
| 560 | Build our dependencies into $WORKDIR/libraries/usr/local |
| 561 | """ |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 562 | print "" |
| 563 | print "Building required libraries" |
| 564 | print "" |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 565 | universal = os.path.join(WORKDIR, 'libraries') |
| 566 | os.mkdir(universal) |
| 567 | os.makedirs(os.path.join(universal, 'usr', 'local', 'lib')) |
| 568 | os.makedirs(os.path.join(universal, 'usr', 'local', 'include')) |
| 569 | |
| 570 | for recipe in LIBRARY_RECIPES: |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 571 | buildRecipe(recipe, universal, ARCHLIST) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 572 | |
| 573 | |
| 574 | |
| 575 | def buildPythonDocs(): |
| 576 | # This stores the documentation as Resources/English.lproj/Docuentation |
| 577 | # inside the framwork. pydoc and IDLE will pick it up there. |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 578 | print "Install python documentation" |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 579 | rootDir = os.path.join(WORKDIR, '_root') |
| 580 | version = getVersion() |
| 581 | docdir = os.path.join(rootDir, 'pydocs') |
| 582 | |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 583 | novername = 'python-docs-html.tar.bz2' |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 584 | name = 'html-%s.tar.bz2'%(getFullVersion(),) |
| 585 | sourceArchive = os.path.join(DEPSRC, name) |
| 586 | if os.path.exists(sourceArchive): |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 587 | print "Using local copy of %s"%(name,) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 588 | |
| 589 | else: |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 590 | print "Downloading %s"%(novername,) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 591 | downloadURL('http://www.python.org/ftp/python/doc/%s/%s'%( |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 592 | getFullVersion(), novername), sourceArchive) |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 593 | print "Archive for %s stored as %s"%(name, sourceArchive) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 594 | |
| 595 | extractArchive(os.path.dirname(docdir), sourceArchive) |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 596 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 597 | os.rename( |
| 598 | os.path.join( |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 599 | os.path.dirname(docdir), 'python-docs-html'), |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 600 | docdir) |
| 601 | |
| 602 | |
| 603 | def buildPython(): |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 604 | print "Building a universal python" |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 605 | |
| 606 | buildDir = os.path.join(WORKDIR, '_bld', 'python') |
| 607 | rootDir = os.path.join(WORKDIR, '_root') |
| 608 | |
| 609 | if os.path.exists(buildDir): |
| 610 | shutil.rmtree(buildDir) |
| 611 | if os.path.exists(rootDir): |
| 612 | shutil.rmtree(rootDir) |
| 613 | os.mkdir(buildDir) |
| 614 | os.mkdir(rootDir) |
| 615 | os.mkdir(os.path.join(rootDir, 'empty-dir')) |
| 616 | curdir = os.getcwd() |
| 617 | os.chdir(buildDir) |
| 618 | |
| 619 | # Not sure if this is still needed, the original build script |
| 620 | # claims that parts of the install assume python.exe exists. |
| 621 | os.symlink('python', os.path.join(buildDir, 'python.exe')) |
| 622 | |
| 623 | # Extract the version from the configure file, needed to calculate |
| 624 | # several paths. |
| 625 | version = getVersion() |
| 626 | |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 627 | print "Running configure..." |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 628 | runCommand("%s -C --enable-framework --enable-universalsdk=%s LDFLAGS='-g -L%s/libraries/usr/local/lib' OPT='-g -O3 -I%s/libraries/usr/local/include' 2>&1"%( |
| 629 | shellQuote(os.path.join(SRCDIR, 'configure')), |
| 630 | shellQuote(SDKPATH), shellQuote(WORKDIR)[1:-1], |
| 631 | shellQuote(WORKDIR)[1:-1])) |
| 632 | |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 633 | print "Running make" |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 634 | runCommand("make") |
| 635 | |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 636 | print "Running make frameworkinstall" |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 637 | runCommand("make frameworkinstall DESTDIR=%s"%( |
| 638 | shellQuote(rootDir))) |
| 639 | |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 640 | print "Running make frameworkinstallextras" |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 641 | runCommand("make frameworkinstallextras DESTDIR=%s"%( |
| 642 | shellQuote(rootDir))) |
| 643 | |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 644 | print "Copying required shared libraries" |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 645 | if os.path.exists(os.path.join(WORKDIR, 'libraries', 'Library')): |
| 646 | runCommand("mv %s/* %s"%( |
| 647 | shellQuote(os.path.join( |
| 648 | WORKDIR, 'libraries', 'Library', 'Frameworks', |
| 649 | 'Python.framework', 'Versions', getVersion(), |
| 650 | 'lib')), |
| 651 | shellQuote(os.path.join(WORKDIR, '_root', 'Library', 'Frameworks', |
| 652 | 'Python.framework', 'Versions', getVersion(), |
| 653 | 'lib')))) |
| 654 | |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 655 | print "Fix file modes" |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 656 | frmDir = os.path.join(rootDir, 'Library', 'Frameworks', 'Python.framework') |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 657 | gid = grp.getgrnam('admin').gr_gid |
| 658 | |
Ronald Oussoren | 360e98c | 2008-12-30 14:16:51 +0000 | [diff] [blame] | 659 | |
| 660 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 661 | for dirpath, dirnames, filenames in os.walk(frmDir): |
| 662 | for dn in dirnames: |
| 663 | os.chmod(os.path.join(dirpath, dn), 0775) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 664 | os.chown(os.path.join(dirpath, dn), -1, gid) |
| 665 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 666 | |
| 667 | for fn in filenames: |
| 668 | if os.path.islink(fn): |
| 669 | continue |
| 670 | |
| 671 | # "chmod g+w $fn" |
| 672 | p = os.path.join(dirpath, fn) |
| 673 | st = os.stat(p) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 674 | os.chmod(p, stat.S_IMODE(st.st_mode) | stat.S_IWGRP) |
| 675 | os.chown(p, -1, gid) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 676 | |
| 677 | # We added some directories to the search path during the configure |
| 678 | # phase. Remove those because those directories won't be there on |
| 679 | # the end-users system. |
| 680 | path =os.path.join(rootDir, 'Library', 'Frameworks', 'Python.framework', |
| 681 | 'Versions', version, 'lib', 'python%s'%(version,), |
| 682 | 'config', 'Makefile') |
| 683 | fp = open(path, 'r') |
| 684 | data = fp.read() |
| 685 | fp.close() |
| 686 | |
| 687 | data = data.replace('-L%s/libraries/usr/local/lib'%(WORKDIR,), '') |
| 688 | data = data.replace('-I%s/libraries/usr/local/include'%(WORKDIR,), '') |
| 689 | fp = open(path, 'w') |
| 690 | fp.write(data) |
| 691 | fp.close() |
| 692 | |
| 693 | # Add symlinks in /usr/local/bin, using relative links |
| 694 | usr_local_bin = os.path.join(rootDir, 'usr', 'local', 'bin') |
| 695 | to_framework = os.path.join('..', '..', '..', 'Library', 'Frameworks', |
| 696 | 'Python.framework', 'Versions', version, 'bin') |
| 697 | if os.path.exists(usr_local_bin): |
| 698 | shutil.rmtree(usr_local_bin) |
| 699 | os.makedirs(usr_local_bin) |
| 700 | for fn in os.listdir( |
| 701 | os.path.join(frmDir, 'Versions', version, 'bin')): |
| 702 | os.symlink(os.path.join(to_framework, fn), |
| 703 | os.path.join(usr_local_bin, fn)) |
| 704 | |
| 705 | os.chdir(curdir) |
| 706 | |
Ronald Oussoren | 360e98c | 2008-12-30 14:16:51 +0000 | [diff] [blame] | 707 | # Remove the 'Current' link, that way we don't accidently mess with an already installed |
| 708 | # version of python |
| 709 | os.unlink(os.path.join(rootDir, 'Library', 'Frameworks', 'Python.framework', 'Versions', 'Current')) |
| 710 | |
| 711 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 712 | |
| 713 | |
| 714 | def patchFile(inPath, outPath): |
| 715 | data = fileContents(inPath) |
| 716 | data = data.replace('$FULL_VERSION', getFullVersion()) |
| 717 | data = data.replace('$VERSION', getVersion()) |
| 718 | data = data.replace('$MACOSX_DEPLOYMENT_TARGET', '10.3 or later') |
| 719 | data = data.replace('$ARCHITECTURES', "i386, ppc") |
| 720 | data = data.replace('$INSTALL_SIZE', installSize()) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 721 | |
| 722 | # This one is not handy as a template variable |
| 723 | data = data.replace('$PYTHONFRAMEWORKINSTALLDIR', '/Library/Frameworks/Python.framework') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 724 | fp = open(outPath, 'wb') |
| 725 | fp.write(data) |
| 726 | fp.close() |
| 727 | |
| 728 | def patchScript(inPath, outPath): |
| 729 | data = fileContents(inPath) |
| 730 | data = data.replace('@PYVER@', getVersion()) |
| 731 | fp = open(outPath, 'wb') |
| 732 | fp.write(data) |
| 733 | fp.close() |
| 734 | os.chmod(outPath, 0755) |
| 735 | |
| 736 | |
| 737 | |
| 738 | def packageFromRecipe(targetDir, recipe): |
| 739 | curdir = os.getcwd() |
| 740 | try: |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 741 | # The major version (such as 2.5) is included in the package name |
| 742 | # because having two version of python installed at the same time is |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 743 | # common. |
| 744 | pkgname = '%s-%s'%(recipe['name'], getVersion()) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 745 | srcdir = recipe.get('source') |
| 746 | pkgroot = recipe.get('topdir', srcdir) |
| 747 | postflight = recipe.get('postflight') |
| 748 | readme = textwrap.dedent(recipe['readme']) |
| 749 | isRequired = recipe.get('required', True) |
| 750 | |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 751 | print "- building package %s"%(pkgname,) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 752 | |
| 753 | # Substitute some variables |
| 754 | textvars = dict( |
| 755 | VER=getVersion(), |
| 756 | FULLVER=getFullVersion(), |
| 757 | ) |
| 758 | readme = readme % textvars |
| 759 | |
| 760 | if pkgroot is not None: |
| 761 | pkgroot = pkgroot % textvars |
| 762 | else: |
| 763 | pkgroot = '/' |
| 764 | |
| 765 | if srcdir is not None: |
| 766 | srcdir = os.path.join(WORKDIR, '_root', srcdir[1:]) |
| 767 | srcdir = srcdir % textvars |
| 768 | |
| 769 | if postflight is not None: |
| 770 | postflight = os.path.abspath(postflight) |
| 771 | |
| 772 | packageContents = os.path.join(targetDir, pkgname + '.pkg', 'Contents') |
| 773 | os.makedirs(packageContents) |
| 774 | |
| 775 | if srcdir is not None: |
| 776 | os.chdir(srcdir) |
| 777 | runCommand("pax -wf %s . 2>&1"%(shellQuote(os.path.join(packageContents, 'Archive.pax')),)) |
| 778 | runCommand("gzip -9 %s 2>&1"%(shellQuote(os.path.join(packageContents, 'Archive.pax')),)) |
| 779 | runCommand("mkbom . %s 2>&1"%(shellQuote(os.path.join(packageContents, 'Archive.bom')),)) |
| 780 | |
| 781 | fn = os.path.join(packageContents, 'PkgInfo') |
| 782 | fp = open(fn, 'w') |
| 783 | fp.write('pmkrpkg1') |
| 784 | fp.close() |
| 785 | |
| 786 | rsrcDir = os.path.join(packageContents, "Resources") |
| 787 | os.mkdir(rsrcDir) |
| 788 | fp = open(os.path.join(rsrcDir, 'ReadMe.txt'), 'w') |
| 789 | fp.write(readme) |
| 790 | fp.close() |
| 791 | |
| 792 | if postflight is not None: |
| 793 | patchScript(postflight, os.path.join(rsrcDir, 'postflight')) |
| 794 | |
| 795 | vers = getFullVersion() |
| 796 | major, minor = map(int, getVersion().split('.', 2)) |
| 797 | pl = Plist( |
| 798 | CFBundleGetInfoString="MacPython.%s %s"%(pkgname, vers,), |
| 799 | CFBundleIdentifier='org.python.MacPython.%s'%(pkgname,), |
| 800 | CFBundleName='MacPython.%s'%(pkgname,), |
| 801 | CFBundleShortVersionString=vers, |
| 802 | IFMajorVersion=major, |
| 803 | IFMinorVersion=minor, |
| 804 | IFPkgFormatVersion=0.10000000149011612, |
| 805 | IFPkgFlagAllowBackRev=False, |
| 806 | IFPkgFlagAuthorizationAction="RootAuthorization", |
| 807 | IFPkgFlagDefaultLocation=pkgroot, |
| 808 | IFPkgFlagFollowLinks=True, |
| 809 | IFPkgFlagInstallFat=True, |
| 810 | IFPkgFlagIsRequired=isRequired, |
| 811 | IFPkgFlagOverwritePermissions=False, |
| 812 | IFPkgFlagRelocatable=False, |
| 813 | IFPkgFlagRestartAction="NoRestart", |
| 814 | IFPkgFlagRootVolumeOnly=True, |
| 815 | IFPkgFlagUpdateInstalledLangauges=False, |
| 816 | ) |
| 817 | writePlist(pl, os.path.join(packageContents, 'Info.plist')) |
| 818 | |
| 819 | pl = Plist( |
| 820 | IFPkgDescriptionDescription=readme, |
| 821 | IFPkgDescriptionTitle=recipe.get('long_name', "MacPython.%s"%(pkgname,)), |
| 822 | IFPkgDescriptionVersion=vers, |
| 823 | ) |
| 824 | writePlist(pl, os.path.join(packageContents, 'Resources', 'Description.plist')) |
| 825 | |
| 826 | finally: |
| 827 | os.chdir(curdir) |
| 828 | |
| 829 | |
| 830 | def makeMpkgPlist(path): |
| 831 | |
| 832 | vers = getFullVersion() |
| 833 | major, minor = map(int, getVersion().split('.', 2)) |
| 834 | |
| 835 | pl = Plist( |
| 836 | CFBundleGetInfoString="MacPython %s"%(vers,), |
| 837 | CFBundleIdentifier='org.python.MacPython', |
| 838 | CFBundleName='MacPython', |
| 839 | CFBundleShortVersionString=vers, |
| 840 | IFMajorVersion=major, |
| 841 | IFMinorVersion=minor, |
| 842 | IFPkgFlagComponentDirectory="Contents/Packages", |
| 843 | IFPkgFlagPackageList=[ |
| 844 | dict( |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 845 | IFPkgFlagPackageLocation='%s-%s.pkg'%(item['name'], getVersion()), |
Ronald Oussoren | 360e98c | 2008-12-30 14:16:51 +0000 | [diff] [blame] | 846 | IFPkgFlagPackageSelection=item['selected'], |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 847 | ) |
| 848 | for item in PKG_RECIPES |
| 849 | ], |
| 850 | IFPkgFormatVersion=0.10000000149011612, |
| 851 | IFPkgFlagBackgroundScaling="proportional", |
| 852 | IFPkgFlagBackgroundAlignment="left", |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 853 | IFPkgFlagAuthorizationAction="RootAuthorization", |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 854 | ) |
| 855 | |
| 856 | writePlist(pl, path) |
| 857 | |
| 858 | |
| 859 | def buildInstaller(): |
| 860 | |
| 861 | # Zap all compiled files |
| 862 | for dirpath, _, filenames in os.walk(os.path.join(WORKDIR, '_root')): |
| 863 | for fn in filenames: |
| 864 | if fn.endswith('.pyc') or fn.endswith('.pyo'): |
| 865 | os.unlink(os.path.join(dirpath, fn)) |
| 866 | |
| 867 | outdir = os.path.join(WORKDIR, 'installer') |
| 868 | if os.path.exists(outdir): |
| 869 | shutil.rmtree(outdir) |
| 870 | os.mkdir(outdir) |
| 871 | |
| 872 | pkgroot = os.path.join(outdir, 'MacPython.mpkg', 'Contents') |
| 873 | pkgcontents = os.path.join(pkgroot, 'Packages') |
| 874 | os.makedirs(pkgcontents) |
| 875 | for recipe in PKG_RECIPES: |
| 876 | packageFromRecipe(pkgcontents, recipe) |
| 877 | |
| 878 | rsrcDir = os.path.join(pkgroot, 'Resources') |
| 879 | |
| 880 | fn = os.path.join(pkgroot, 'PkgInfo') |
| 881 | fp = open(fn, 'w') |
| 882 | fp.write('pmkrpkg1') |
| 883 | fp.close() |
| 884 | |
| 885 | os.mkdir(rsrcDir) |
| 886 | |
| 887 | makeMpkgPlist(os.path.join(pkgroot, 'Info.plist')) |
| 888 | pl = Plist( |
| 889 | IFPkgDescriptionTitle="Universal MacPython", |
| 890 | IFPkgDescriptionVersion=getVersion(), |
| 891 | ) |
| 892 | |
| 893 | writePlist(pl, os.path.join(pkgroot, 'Resources', 'Description.plist')) |
| 894 | for fn in os.listdir('resources'): |
| 895 | if fn == '.svn': continue |
| 896 | if fn.endswith('.jpg'): |
| 897 | shutil.copy(os.path.join('resources', fn), os.path.join(rsrcDir, fn)) |
| 898 | else: |
| 899 | patchFile(os.path.join('resources', fn), os.path.join(rsrcDir, fn)) |
| 900 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 901 | shutil.copy("../../LICENSE", os.path.join(rsrcDir, 'License.txt')) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 902 | |
| 903 | |
| 904 | def installSize(clear=False, _saved=[]): |
| 905 | if clear: |
| 906 | del _saved[:] |
| 907 | if not _saved: |
| 908 | data = captureCommand("du -ks %s"%( |
| 909 | shellQuote(os.path.join(WORKDIR, '_root')))) |
| 910 | _saved.append("%d"%((0.5 + (int(data.split()[0]) / 1024.0)),)) |
| 911 | return _saved[0] |
| 912 | |
| 913 | |
| 914 | def buildDMG(): |
| 915 | """ |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 916 | Create DMG containing the rootDir. |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 917 | """ |
| 918 | outdir = os.path.join(WORKDIR, 'diskimage') |
| 919 | if os.path.exists(outdir): |
| 920 | shutil.rmtree(outdir) |
| 921 | |
| 922 | imagepath = os.path.join(outdir, |
| 923 | 'python-%s-macosx'%(getFullVersion(),)) |
| 924 | if INCLUDE_TIMESTAMP: |
| 925 | imagepath = imagepath + '%04d-%02d-%02d'%(time.localtime()[:3]) |
| 926 | imagepath = imagepath + '.dmg' |
| 927 | |
| 928 | os.mkdir(outdir) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 929 | runCommand("hdiutil create -volname 'Universal MacPython %s' -srcfolder %s %s"%( |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 930 | getFullVersion(), |
| 931 | shellQuote(os.path.join(WORKDIR, 'installer')), |
| 932 | shellQuote(imagepath))) |
| 933 | |
| 934 | return imagepath |
| 935 | |
| 936 | |
| 937 | def setIcon(filePath, icnsPath): |
| 938 | """ |
| 939 | Set the custom icon for the specified file or directory. |
| 940 | |
| 941 | For a directory the icon data is written in a file named 'Icon\r' inside |
| 942 | the directory. For both files and directories write the icon as an 'icns' |
| 943 | resource. Furthermore set kHasCustomIcon in the finder flags for filePath. |
| 944 | """ |
| 945 | ref, isDirectory = Carbon.File.FSPathMakeRef(icnsPath) |
| 946 | icon = Carbon.Icn.ReadIconFile(ref) |
| 947 | del ref |
| 948 | |
| 949 | # |
| 950 | # Open the resource fork of the target, to add the icon later on. |
| 951 | # For directories we use the file 'Icon\r' inside the directory. |
| 952 | # |
| 953 | |
| 954 | ref, isDirectory = Carbon.File.FSPathMakeRef(filePath) |
| 955 | |
| 956 | if isDirectory: |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 957 | # There is a problem with getting this into the pax(1) archive, |
| 958 | # just ignore directory icons for now. |
| 959 | return |
| 960 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 961 | tmpPath = os.path.join(filePath, "Icon\r") |
| 962 | if not os.path.exists(tmpPath): |
| 963 | fp = open(tmpPath, 'w') |
| 964 | fp.close() |
| 965 | |
| 966 | tmpRef, _ = Carbon.File.FSPathMakeRef(tmpPath) |
| 967 | spec = Carbon.File.FSSpec(tmpRef) |
| 968 | |
| 969 | else: |
| 970 | spec = Carbon.File.FSSpec(ref) |
| 971 | |
| 972 | try: |
| 973 | Carbon.Res.HCreateResFile(*spec.as_tuple()) |
| 974 | except MacOS.Error: |
| 975 | pass |
| 976 | |
| 977 | # Try to create the resource fork again, this will avoid problems |
| 978 | # when adding an icon to a directory. I have no idea why this helps, |
| 979 | # but without this adding the icon to a directory will fail sometimes. |
| 980 | try: |
| 981 | Carbon.Res.HCreateResFile(*spec.as_tuple()) |
| 982 | except MacOS.Error: |
| 983 | pass |
| 984 | |
| 985 | refNum = Carbon.Res.FSpOpenResFile(spec, fsRdWrPerm) |
| 986 | |
| 987 | Carbon.Res.UseResFile(refNum) |
| 988 | |
| 989 | # Check if there already is an icon, remove it if there is. |
| 990 | try: |
| 991 | h = Carbon.Res.Get1Resource('icns', kCustomIconResource) |
| 992 | except MacOS.Error: |
| 993 | pass |
| 994 | |
| 995 | else: |
| 996 | h.RemoveResource() |
| 997 | del h |
| 998 | |
| 999 | # Add the icon to the resource for of the target |
| 1000 | res = Carbon.Res.Resource(icon) |
| 1001 | res.AddResource('icns', kCustomIconResource, '') |
| 1002 | res.WriteResource() |
| 1003 | res.DetachResource() |
| 1004 | Carbon.Res.CloseResFile(refNum) |
| 1005 | |
| 1006 | # And now set the kHasCustomIcon property for the target. Annoyingly, |
| 1007 | # python doesn't seem to have bindings for the API that is needed for |
| 1008 | # this. Cop out and call SetFile |
| 1009 | os.system("/Developer/Tools/SetFile -a C %s"%( |
| 1010 | shellQuote(filePath),)) |
| 1011 | |
| 1012 | if isDirectory: |
| 1013 | os.system('/Developer/Tools/SetFile -a V %s'%( |
| 1014 | shellQuote(tmpPath), |
| 1015 | )) |
| 1016 | |
| 1017 | def main(): |
| 1018 | # First parse options and check if we can perform our work |
| 1019 | parseOptions() |
| 1020 | checkEnvironment() |
| 1021 | |
| 1022 | os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.3' |
| 1023 | |
| 1024 | if os.path.exists(WORKDIR): |
| 1025 | shutil.rmtree(WORKDIR) |
| 1026 | os.mkdir(WORKDIR) |
| 1027 | |
| 1028 | # Then build third-party libraries such as sleepycat DB4. |
| 1029 | buildLibraries() |
| 1030 | |
| 1031 | # Now build python itself |
| 1032 | buildPython() |
| 1033 | buildPythonDocs() |
| 1034 | fn = os.path.join(WORKDIR, "_root", "Applications", |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 1035 | "Python %s"%(getVersion(),), "Update Shell Profile.command") |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1036 | patchFile("scripts/postflight.patch-profile", fn) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1037 | os.chmod(fn, 0755) |
| 1038 | |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 1039 | folder = os.path.join(WORKDIR, "_root", "Applications", "Python %s"%( |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1040 | getVersion(),)) |
| 1041 | os.chmod(folder, 0755) |
| 1042 | setIcon(folder, "../Icons/Python Folder.icns") |
| 1043 | |
| 1044 | # Create the installer |
| 1045 | buildInstaller() |
| 1046 | |
| 1047 | # And copy the readme into the directory containing the installer |
| 1048 | patchFile('resources/ReadMe.txt', os.path.join(WORKDIR, 'installer', 'ReadMe.txt')) |
| 1049 | |
| 1050 | # Ditto for the license file. |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1051 | shutil.copy('../../LICENSE', os.path.join(WORKDIR, 'installer', 'License.txt')) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1052 | |
| 1053 | fp = open(os.path.join(WORKDIR, 'installer', 'Build.txt'), 'w') |
Benjamin Peterson | 623918e | 2008-12-20 22:50:25 +0000 | [diff] [blame] | 1054 | print >> fp, "# BUILD INFO" |
| 1055 | print >> fp, "# Date:", time.ctime() |
| 1056 | print >> fp, "# By:", pwd.getpwuid(os.getuid()).pw_gecos |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1057 | fp.close() |
| 1058 | |
| 1059 | # Custom icon for the DMG, shown when the DMG is mounted. |
| 1060 | shutil.copy("../Icons/Disk Image.icns", |
| 1061 | os.path.join(WORKDIR, "installer", ".VolumeIcon.icns")) |
| 1062 | os.system("/Developer/Tools/SetFile -a C %s"%( |
| 1063 | os.path.join(WORKDIR, "installer", ".VolumeIcon.icns"))) |
| 1064 | |
| 1065 | |
| 1066 | # And copy it to a DMG |
| 1067 | buildDMG() |
| 1068 | |
| 1069 | |
| 1070 | if __name__ == "__main__": |
| 1071 | main() |