===============================
Windows Installer Build Scripts
===============================

We use `msys2 <https://msys2.github.io/>`__ for creating the Windows installer
and development on Windows. The setup was modified from 
`QuodLibet <https://github.com/quodlibet/quodlibet>` to our needs.

For those interested, the main changes were related to fixing dependencies and
restraining some over-zealous clean up actions before packaging. These resulted
in missing python modules (i.e. numpy.testing and matplotlib.testing).


Development
-----------

For developing on Windows you have two choices.

1) Just use an existing PyXRD installation plus a git checkout:

   * Clone the git repo with some git client
   * Download and install the latest installer build:
     https://github.com/mathijs-dumon/pyxrd/releases/download/latest/pyxrd-latest-installer.exe
   * Go to pyxrd.py in the git checkout and run
     ``%PROGRAMFILES(X86)%\PyXRD\bin\python.exe pyxrd.py``.

2) Use proper msys2 environment


Setting Up the MSYS2 Environment
--------------------------------

* Download msys2 64-bit from https://msys2.github.io/
* Follow instructions on https://msys2.github.io/
* Execute ``C:\msys64\mingw32.exe``
* Run ``pacman -S git`` to install git
* Run ``git clone https://github.com/mathijs-dumon/pyxrd.git``
* Run ``cd pyxrd/win_installer`` to end up where this README exists.
* Execute ``./bootstrap.sh`` to install all the needed dependencies.
* Now go to the git root ``cd ..``
* To run PyXRD execute ``python3 -m pyxrd``


Creating an Installer
---------------------

Simply run ``./build.sh [git-tag]`` and both the installer and the portable
installer should appear in this directory.

You should occasionally update the matplotlib package to a more recent version
(see below).

You can pass a git tag ``./build.sh release-3.8.0`` to build a specific tag or
pass nothing to build master. Note that it will clone from this repository and
not from github so any commits present locally will be cloned as well.


Updating MSYS2 matplotlib
-------------------------

The default MSYS2 matplotlib package is compiled against Qt and not GTK. This 
installs a bunch of unneeded stuff and also means that matplotlib won't have 
GTK support. A modified build file is available at 
misc/mingw-w64-python-matplotlib. To build this:

* Run ``cd pyxrd/win_installer/misc/mingw-w64-python-matplotlib``
* Run ``makepkg``
* Run ``cp mingw-w64-i686-python3-matplotlib-*-any.pkg.tar ../``


Updating an Existing Installer
------------------------------

We directly follow msys2 upstream so building the installer two weeks later
might result in newer versions of dependencies being used. To reduce the risk
of stable release breakage you can use an existing installer and just install
a newer PyXRD version into it and then repack it.

``./rebuild.sh pyxrd-3.8.0-installer.exe [git-tag]``
