commercialhaskell / commercialhaskell/stack

stack datadir option writes to datadir during build, breaking DESTDIR, unlike cabal

Open
#5,026 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
4.1k
Forks
850
Avg merge
10h 37m
Merged PRs (30d)
4

Description

I believe that this `stack` behavior is a bug:

Specifying `stack`'s `--datadir=` option in `stack.yaml` causes `stack` to **write cabal's `data-files` to `datadir`** during `stack build`. This breaks package manager GNU `DESTDIR` capability, as discussed in https://github.com/commercialhaskell/stack/issues/848. Here is an[ example](https://github.com/macports/macports-ports/blob/3b48a2f76c220d827fc3775ca266b9a2ad674751/www/adblock2privoxy/Portfile) automated build that illustrates the problem.

In contrast, specifying `datadir` in the `cabal` file `Paths_packagename.hs`, causes `stack` to write cabal's `data-files` to the default `.stack-work` location during the build, **and** produce a binary with a correctly hardcoded path in `PREFIX`. This approach was [described](http://neilmitchell.blogspot.com/2008/02/adding-data-files-using-cabal.html) years ago by [hlint](https://github.com/ndmitchell/hlint)'s author @ndmitchell.

Here is the `stack.yaml' configuration that produces the issue:
```
configure-options:
packagename:
- --datadir=/path/to/my/datadir
```

Here is an automated `stack` build that solves the issue with related files:
* https://github.com/macports/macports-ports/blob/e18fe88466477b20da595346ebce8eab839b9fbc/www/adblock2privoxy/Portfile
* https://github.com/macports/macports-ports/blob/e18fe88466477b20da595346ebce8eab839b9fbc/www/adblock2privoxy/files/Paths_adblock2privoxy.hs

Also noted for posterity: setting the environment variable `packagename_datadir` at runtime overrides the binary's hardcoded `packagename_datadir` path.

I believe that `stack`'s behavior should be the same as setting `datadir` in `Paths_packagename.hs`, which would fix a longstanding problem of hardcoded paths of the build directory in `stack` binaries when `cabal` `data-files` exist in `packagename.cabal`.

This is related to:
* https://github.com/haskell/cabal/issues/462
* https://github.com/haskell/cabal/issues/3586
* https://github.com/commercialhaskell/stack/issues/848
* https://github.com/commercialhaskell/stack/issues/4857

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.