bii internals: Automating MacOS pkg generation

In a previous posts we talked about how we cythonized and packaged biicode with pyinstaller. Now we will explain how to generate installers for the different systems, starting with mac. The problem with pkg generation is that most of the existing tutorials and references are xcode oriented, and we just wanted to use plain console.

Let’s get started on how generate a mac installer:

Before packaging we need to prepare a set of additional files: license and welcome text, background img, postinstall script and the Distribution.xml.

Distribution.xml is a distribution definition file which defines the installation experience for the installer package that contains it, you can read about its different options in the Apple developers page. A minimal Distribution.xml looks like this:

postinstall script is a script that runs as super user after installation is complete. In our case it will set permissions and create a symbolic link in the PATH:

Welcome.rtf is the rich text that appears in the first step of the installation wizard, that looks like this:

Biicode installation Wizard: Welcome

Biicode installation Wizard: Welcome

background.png is the image containing the bee you se above.

license.rtf contains the license users need to accept in the next step.

Biicode installation Wizard: License

Biicode installation Wizard: License

Both Welcome and license can be in different languages with the proper suffixes so they will display in the user’s language.

In our automation repo we have all these files in a folder like this:

Now that we have everything set up we can start packaging, the main script looks like this:

This script, creates a temporary directory to work in, creates the base package, patches the distribution file and creates the final pkg to release. binary_path is the path to the app processed by PyInstaller.

So we copy the previously mentioned files (resources) to a Resources file in the pyinstaller generated folder and invoke pkgbuild.

pkgbuild builds an OS X Installer component package from on-disk files. A “component package” contains payload to be installed by the OS X Installer. Although a component
package can be installed on its own, it is typically incorporated into a product archive, along with a “distribution” and localized resources, using productbuild.

So then we can create the final product package:

productbuild builds a product archive for the OS X Installer or the Mac App Store. A product archive is a flat file with a .pkg extension.  productbuild creates a deployable product archive, which can be used with the OS X Installer, or submitted to the Mac App Store.

An additional step would be signing the package so it comes from a “trusted” developer (and you dont need to right-click on it to install it) but we are skipping that step for the moment.

Hope you enjoy packaging!

Stay tuned


Related Posts