simonmar/happy — pull request #23 by kini (2014-06-27 23:19:39+00:00)
Title: Make build more robust on systems lacking Happy

Happy cannot be built inside a Cabal sandbox on a system that has no
existing version of Happy available.

Right now, Happy depends on itself, in that the source code of Happy
includes a couple of .ly files which themselves need to be parsed by
Happy during the build process.

The current way to deal with this seems to be to ship a Happy source
tarball containing "build artifacts" (actually just Haskell files,
preprocessed from .ly files by Happy). That way, if someone tries to
build Happy from the tarball on a system which doesn't already have some
version of Happy available, the build process will see that these .hs
files already exist, and not try to call happy on the corresponding .ly
files.

This is a brittle solution because when creating the tarball one must
know the location, relative to the unpacked tarball root directory, in
which the build is to take place, in order to ensure that the build
artifacts are lying in the correct place for the build process to see
them. This causes the problem with Cabal sandboxes, because in sandbox
builds, the build directory does not have a predictable location -- not
only does it contain a random nonce in its path, but it could also be in
a completely different location, if someone were using `cabal sandbox
add-source `.

This commit fixes the above issue, by handling the usage and updating of
saved build artifacts in a more intelligent way inside Setup.lhs.

During the build process, Setup.lhs will check whether Happy already
exists on the system.

- If so, it will copy the desired build artifacts from the build
directory (wherever it is) to ./artifacts/ in the repository root
after the build is completed

- If not, it will copy the necessary build artifacts from ./artifacts/
in the repository root to the build directory (wherever it is) before
the build begins.

Files changed:
* Setup.lhs: Add logic for using/preserving build artifacts
* happy.cabal: Add build artifacts to extra-source-files so that sandbox
builds will know about them and copy them