Permalink
Browse files

add os x bulid scripts

  • Loading branch information...
1 parent d150f85 commit cfa1a0f1d1b37c2eeb519e6524f082484917071a @jarrodmillman jarrodmillman committed Nov 25, 2008
Showing with 164 additions and 0 deletions.
  1. +32 −0 tools/osx/README.txt
  2. +83 −0 tools/osx/build.py
  3. +49 −0 tools/osx/install_and_test.py
View
@@ -0,0 +1,32 @@
+==================================
+ Building an OSX binary for scipy
+==================================
+
+This directory contains the scripts to build a universal binary for
+OSX. The binaries work on OSX 10.4 and 10.5.
+
+The docstring in build.py may contain more current details.
+
+Requirements
+============
+
+* bdist_mpkg v0.4.3
+
+Build
+=====
+
+The build script will build a scipy distribution using bdist_mpkg and
+create the mac package (mpkg) bundled in a disk image (dmg). To run
+the build script::
+
+ python build.py
+
+Install and test
+----------------
+
+The *install_and_test.py* script will find the scipy*.mpkg, install it
+using the Mac installer and then run the scipy test suite. To run the
+install and test::
+
+ python install_and_test.py
+
View
@@ -0,0 +1,83 @@
+"""Python script to build the OSX universal binaries.
+
+This is a simple script, most of the heavy lifting is done in bdist_mpkg.
+
+To run this script: 'python build.py'
+
+Requires a svn version of scipy is installed, svn is used to revert
+file changes made to the docs for the end-user install. Installer is
+built using sudo so file permissions are correct when installed on
+user system. Script will prompt for sudo pwd.
+
+"""
+
+import os
+import shutil
+import subprocess
+from getpass import getuser
+
+SRC_DIR = '../../'
+
+BUILD_DIR = 'build'
+DIST_DIR = 'dist'
+
+def remove_dirs():
+ print 'Removing old build and distribution directories...'
+ print """The distribution is built as root, so the files have the correct
+ permissions when installed by the user. Chown them to user for removal."""
+ if os.path.exists(BUILD_DIR):
+ cmd = 'sudo chown -R %s %s' % (getuser(), BUILD_DIR)
+ shellcmd(cmd)
+ shutil.rmtree(BUILD_DIR)
+ if os.path.exists(DIST_DIR):
+ cmd = 'sudo chown -R %s %s' % (getuser(), DIST_DIR)
+ shellcmd(cmd)
+ shutil.rmtree(DIST_DIR)
+
+def build_dist():
+ print 'Building distribution... (using sudo)'
+ cmd = 'sudo python setupegg.py bdist_mpkg'
+ shellcmd(cmd)
+
+def build_dmg():
+ print 'Building disk image...'
+ # Since we removed the dist directory at the start of the script,
+ # our pkg should be the only file there.
+ pkg = os.listdir(DIST_DIR)[0]
+ fn, ext = os.path.splitext(pkg)
+ dmg = fn + '.dmg'
+ srcfolder = os.path.join(DIST_DIR, pkg)
+ dstfolder = os.path.join(DIST_DIR, dmg)
+ # build disk image
+ cmd = 'sudo hdiutil create -srcfolder %s %s' % (srcfolder, dstfolder)
+ shellcmd(cmd)
+
+def shellcmd(cmd, verbose=True):
+ """Call a shell command."""
+ if verbose:
+ print cmd
+ try:
+ subprocess.check_call(cmd, shell=True)
+ except subprocess.CalledProcessError, err:
+ msg = """
+ Error while executing a shell command.
+ %s
+ """ % str(err)
+ raise Exception(msg)
+
+def build():
+
+ # change to source directory
+ cwd = os.getcwd()
+ os.chdir(SRC_DIR)
+
+ # build distribution
+ remove_dirs()
+ build_dist()
+ build_dmg()
+
+ # change back to original directory
+ os.chdir(cwd)
+
+if __name__ == '__main__':
+ build()
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+"""Install the built package and run the tests."""
+
+import os
+
+# FIXME: Should handle relative import better!
+#from .build import DIST_DIR
+from build import SRC_DIR, DIST_DIR, shellcmd
+
+clrgreen = '\033[0;32m'
+clrnull = '\033[0m'
+# print '\033[0;32m foobar \033[0m'
+def color_print(msg):
+ """Add color to this print output."""
+ clrmsg = clrgreen + msg + clrnull
+ print clrmsg
+
+distdir = os.path.join(SRC_DIR, DIST_DIR)
+
+# Find the package and build abspath to it
+pkg = None
+filelist = os.listdir(distdir)
+for fn in filelist:
+ if fn.endswith('mpkg'):
+ pkg = fn
+ break
+if pkg is None:
+ raise IOError, 'Package is not found in directory %s' % distdir
+
+pkgpath = os.path.abspath(os.path.join(SRC_DIR, DIST_DIR, pkg))
+color_print('Installing package: %s' % pkgpath)
+
+# Run the installer
+print
+color_print('Installer requires admin rights, you will be prompted for sudo')
+print
+cmd = 'sudo installer -verbose -package %s -target /' % pkgpath
+#color_print(cmd)
+shellcmd(cmd)
+
+# Null out the PYTHONPATH so we're sure to test the Installed version of scipy
+os.environ['PYTHONPATH'] = '0'
+
+print
+color_print('Install successful!')
+color_print('Running scipy test suite!')
+print
+import scipy
+scipy.test()

0 comments on commit cfa1a0f

Please sign in to comment.