Skip to content

Building an OS X Distribution

George Dietz edited this page Jun 10, 2013 · 40 revisions

Easy:

  1. Run ./make_mac_build from WITHIN the src folder and that will do everything aside from making the executable have the right icon.
  2. Change app icon to that of the .icns file in the images subdirectory.

Notes:

  • There is a function in open_meta_mac.py that creates pangorc with the path to pango.modules as required at run-time. This solved a problem where the text in graphs produced by R showed up as boxes.
  • Without the r_tmp folder in the same directory as the app, R will not be able to make graphs
  • These instructions were written while building a system where all the development stuff was installed using macports. (R, rpy2, PyQt4, python)
  • Make sure you package the zip file you release with the app, sample_data, and r_tmp folder

POST MOUNTAIN-LION

First, delete the app at dev/OpenMetaAnalyst currently (otherwise you will get errors when you try to build). You will be re-using things in dev/frozen/prototype, DO NOT DELETE THIS.

cd dev/OpenMetaAanalyst sudo python-oma setup_redux.py build

Then copy dylibs from the dylibs directory into the dev/frozen/OpenMetaAnalyst.app/Contents/MacOS (see below for notes). Further, you'll need to grab the R_dist folder from an existing build and drop this in the same directory. (Overwrite open_meta_r as appropriate). Note that R libs live locally @:

/Library/Frameworks/R.framework/Versions/2.13/Resources/library

Finally, open meta.ico and 'get info' on OpenMetaAnalyst.app. Then copy the icon and paste it into the icon spot in the info panel of the app.

New issues with OS X 10.7 (mountain lion). This move caused all sorts of problems. The biggest issue seems to be with libiconv.2.dylib. But first, a summary of what we're doing now.

  • We now build an app. This is done with cx_Freeze -- output goes to dev/frozen.

In general, check your dependency paths as follows:

otool -L libpango-1.0.0.dylib

The cx_Freeze script should change all absolute paths to relative. /opt/local should not appear in the output from doing the above. However, if it does that same file better be distributed in the OpenMeta directory. This will be found because you set the dyld_fallback path in the init_script (open_meta_mac.py)

There are issues with libiconv. Terrible, terrible issues. QT depends on version 7; everything else on version 8 (which I believe shipped with 10.7). Hence I distribute two versions, calling version 8 libiconv.2.8.dylib. I then change the pointers of the libraries that depend on libiconv.8 to this library, as follows:

sudo install_name_tool -change /opt/local/lib/libiconv.2.dylib @executable_path/libiconv.2.8.dylib libpango-1.0.0.dylib

You shouldn't need to do this again, so long as you copy the *.dylibs in the "dylibs" directory (in Frozen). (You may want to explicitly rename libiconv.2 to libiconv.2.7 in the future, in case someone happens to have this version at /opt/local or whatever on their own machine -- the program will throw up if it tries to load this guy.)

Another small note on Mac Applications; when you launch the program via double-clicking, the relative R directory seems to be the very top level (i.e., the folder from where the program was launched). For whatever reason, the OS will often not let Python (or R) create sub-directories here. Notably, this means r_tmp will not be created, which means when you try and run an analysis, it will fail. Confusingly, when you invoke the application manually, i.e., via:

OpenMetaAnalyst.app/Contents/MacOS/meta_form

It creates the tmp dir as expected (and will subsequently run fine afterward via double-click launch). As a short-term fix, I have added an r_tmp folder to the top-level directory in the distribution.

OUTDATED -- kept for posterity

We have moved to using cx-freeze for creating mac builds. NOTE, the immediately following is slightly outdated.

Once cxfreeze is built and in your path, the following should do the trick:

cxfreeze path/to/meta_form.py

Be careful to use the correct paths; for whatever reason it complains otherwise. For example, on my laptop:

$ build/scripts-2.7/cxfreeze /Users/byronwallace/dev/OpenMeta-analyst-/meta_form.py

(From $HOME).

This will generate a double-clickable executable (by default in the "dist" directory of whatever directory cx_freeze is in; you can change this using --target=... (I think)). Hurray!

There's also the issue of setting a pointer to (our) R distribution. This can be done using cx-freeze's initscript argument, as follows

byronwallace$ build/scripts-2.7/cxfreeze /Users/byronwallace/dev/OpenMeta-analyst-/meta_form.py --init-script=/Users/byronwallace/dev/OpenMeta-analyst-/open_meta_mac.py

This tells cx_freeze to run open_meta_mac first -- this script sets the R_HOME variable accordingly.

There are other issues. First, the program will try to load dynamic libraries from absolute paths that don't exist on target machines (/opt/local/...), even those the libraries it's trying to load are in the "dist" directory. You can fix this by exporting the environment variable DYLD_LIBRARY_PATH to point to the dist directory, e.g.,

export DYLD_LIBRARY_PATH=/Users/issa/Desktop/dist

This has been moved to the open_meta_mac.py script, like R_HOME. It usually works, however, on some machines it doesn't seem to work for some unknown/frustrating reason. Indeed, in such cases, doing the above at the console and then launching the program does the trick. This should be exactly equivalent to doing it at the console manually. sigh.

In general, sometimes R libraries/packages rely on dylib files. In such cases, make sure you distribute the corresponding files in the dist directory! Otherwise you will get complaints that they don't exist/cannot be loaded.

**Crucially, you need to replace the "libiconv" library in the generated binary -- otherwise you will get "_iconv" errors. More recent versions of this will suffice. I resolved the issue by copying the version on my local machine (dated 6/24/10): this is saved locally in the tellingly named 'use-this-libconv' directory, or look for "libiconv.dylib" and overwrite the current version in the "dist" directory. **

Finally, you'll also need to copy the qtmenu.nib file to the "dist" directory.

To update the R library, build openmetar in the usual way (via console) and install it. then copy the built library to the R_dist directory. This is at:

/Library/Frameworks/R.framework/Versions/2.10/Resources/library

A last note to self: make sure you use the correct python path, i.e., do

export PATH=/Library/Frameworks/Python.framework/Versions/2.7/bin/:$PATH Before building.


With 4.3:

sudo cx_Freeze-4.3/build/scripts-2.7/cxfreeze OpenMeta-analyst-/meta_form.py --init-script=/Users/bwallace/dev/cx_Freeze-4.3/initscripts/open_meta_mac.py

--