haskell / haskell/cabal

Do not pass environment variables to `happy`/`alex`, or at least allow a way to filter

Open
#10,072 3 comments 0 reactions 0 assignees View on GitHub
needs triage type: bug
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

**Describe the bug**

`happy` uses template files that need to be distributed with its executable, hence it uses the [`data-files` field(?)](https://github.com/haskell/happy/blob/535ce96533fb693a8a4441b0ac17cdb78bddfeec/packages/backend-lalr/happy-backend-lalr.cabal#L43). This causes troubles during bootstrapping, which I will explain now. I have also attached a more minimal reproducer below, but the use case is important as well.

In https://github.com/haskell/happy/issues/262 and https://github.com/haskell/happy/issues/274 we have trouble bootstrapping `happy-2`. That is because while building `happy-2` with `cabal`, the `$happy_datadir` environment variable is set to point to somewhere in the working directory (I have no idea why that is necessary). But the bootstrapping process (for package `happy-tabular`) runs a preinstalled `happy-1.20` to compile happy's own grammar file. This run reads the `$happy_datadir` variable and consequently looks for its template file in the wrong location, leading to abrupt error.

**To Reproduce**
Steps to reproduce the behavior:

[(Files as a zip instead of heredoc)](https://github.com/user-attachments/files/15635061/datadir-error.zip)

```
$ cat << EOF > datadir-error.cabal
name: datadir-error
version: 0.1.0.0
build-type: Simple
library
exposed-modules: Parser
hs-source-dirs: .
EOF
$ cat << EOF > Parser.y
{
module Parser where
}
%name foo

%%

foo : { }
$ happy_datadir=. cabal build
Resolving dependencies...
Build profile: -w ghc-9.4.8 -O1
In order, the following will be built (use -v for more details):
- datadir-error-0.1.0.0 (lib:datadir-error) (first run)
Warning: datadir-error.cabal:0:0: A package using section syntax must specify
at least
'cabal-version: >= 1.2'.
Configuring datadir-error-0.1.0.0...
Preprocessing library for datadir-error-0.1.0.0..
happy: ./HappyTemplate-arrays-coerce: openFile: does not exist (No such file or directory)
Error: cabal: Failed to build datadir-error-0.1.0.0.
```

**Expected behavior**
Produce a `Parser.hs` file, try to build it, *despite* me setting an invalid environment variable for `happy`.

**System information**
- Ubuntu 22.04
- Cabal 3.10.2.1, GHC 9.4.8

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.