haskell / haskell/cabal

Wrong environment passed to happy build tool

Open
#10,633 1 comment 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**

This was initially reported in https://github.com/haskell/cabal/issues/10072#issuecomment-2513888478 but I'm not sure it's the same issue so I don't want to hijack Sebastian's ticket.

1. I have happy 2.0.2 globally installed (`/usr/bin/happy`)
2. For some reason Cabal puts happy 2.1.3 in the build plan and builds it
3. But then my globally installed happy 2.0.2 is called with the environment variable `happy_lib_datadir` set to `/path/to/happy-lib-2.1.3/data`, hence it uses the wrong `HappyTemplate.hs` and the generated code doesn't compile.

**To Reproduce**

Steps to reproduce the behavior:

In GHC's source tree:

```
# Preparing source files...
mkdir -p _build/stage0/src/
cp -rf ./libraries _build/stage0/src/
cp -rf ./compiler _build/stage0/src/libraries/ghc
cp -rf ./ghc _build/stage0/src/ghc-bin
cp -rf ./utils _build/stage0/src/

## Substituting variables
cp _build/stage0/src/ghc-bin/ghc-bin.cabal{.in,}
cp _build/stage0/src/libraries/ghc/ghc.cabal{.in,}
cp _build/stage0/src/libraries/ghc/GHC/CmmToLlvm/Version/Bounds.hs{.in,}
cp _build/stage0/src/libraries/ghc-boot/ghc-boot.cabal{.in,}
cp _build/stage0/src/libraries/ghc-boot-th/ghc-boot-th.cabal{.in,}
cp _build/stage0/src/libraries/ghc-heap/ghc-heap.cabal{.in,}
cp _build/stage0/src/libraries/ghci/ghci.cabal{.in,}
cp _build/stage0/src/utils/ghc-pkg/ghc-pkg.cabal{.in,}

sed -i 's/@ProjectVersion@/9.13/' _build/stage0/src/ghc-bin/ghc-bin.cabal
sed -i 's/@ProjectVersionMunged@/9.13/' _build/stage0/src/ghc-bin/ghc-bin.cabal
sed -i 's/@ProjectVersion@/9.13/' _build/stage0/src/libraries/ghc/ghc.cabal
sed -i 's/@ProjectVersionMunged@/9.13/' _build/stage0/src/libraries/ghc/ghc.cabal
sed -i 's/@ProjectVersion@/9.13/' _build/stage0/src/libraries/ghc-boot/ghc-boot.cabal
sed -i 's/@ProjectVersionMunged@/9.13/' _build/stage0/src/libraries/ghc-boot/ghc-boot.cabal
sed -i 's/@ProjectVersion@/9.13/' _build/stage0/src/libraries/ghc-boot-th/ghc-boot-th.cabal
sed -i 's/@ProjectVersionMunged@/9.13/' _build/stage0/src/libraries/ghc-boot-th/ghc-boot-th.cabal
sed -i 's/@Suffix@//' _build/stage0/src/libraries/ghc-boot-th/ghc-boot-th.cabal
sed -i 's/@SourceRoot@/./' _build/stage0/src/libraries/ghc-boot-th/ghc-boot-th.cabal
sed -i 's/@ProjectVersion@/9.13/' _build/stage0/src/libraries/ghc-heap/ghc-heap.cabal
sed -i 's/@ProjectVersionMunged@/9.13/' _build/stage0/src/libraries/ghc-heap/ghc-heap.cabal
sed -i 's/@ProjectVersionForLib@/9.13/' _build/stage0/src/libraries/ghc-heap/ghc-heap.cabal
sed -i 's/@ProjectVersion@/9.13/' _build/stage0/src/libraries/ghci/ghci.cabal
sed -i 's/@ProjectVersionMunged@/9.13/' _build/stage0/src/libraries/ghci/ghci.cabal
sed -i 's/@ProjectVersionForLib@/9.13/' _build/stage0/src/libraries/ghci/ghci.cabal
sed -i 's/@ProjectVersion@/9.13/' _build/stage0/src/utils/ghc-pkg/ghc-pkg.cabal
sed -i 's/@ProjectVersionMunged@/9.13/' _build/stage0/src/utils/ghc-pkg/ghc-pkg.cabal
sed -i 's/@ProjectVersionForLib@/9.13/' _build/stage0/src/utils/ghc-pkg/ghc-pkg.cabal

sed -i 's/@LlvmMinVersion@/13/' _build/stage0/src/libraries/ghc/GHC/CmmToLlvm/Version/Bounds.hs
sed -i 's/@LlvmMaxVersion@/20/' _build/stage0/src/libraries/ghc/GHC/CmmToLlvm/Version/Bounds.hs

# Building...
mkdir -p _build/stage0/cabal/
mkdir -p _build/stage0/bin/

$(CABAL) build --project-file=cabal.project-stage0 \
ghc-bin:ghc ghc-pkg:ghc-pkg genprimopcode:genprimopcode deriveConstants:deriveConstants \
-j --builddir=_build/stage0/cabal/
```

```
-- cabal.project-stage0
packages:
./_build/stage0/src/ghc-bin/
./_build/stage0/src/libraries/ghc
./_build/stage0/src/libraries/directory/
./_build/stage0/src/libraries/file-io/
./_build/stage0/src/libraries/filepath/
./_build/stage0/src/libraries/ghc-platform/
./_build/stage0/src/libraries/ghc-boot/
./_build/stage0/src/libraries/ghc-boot-th/
./_build/stage0/src/libraries/ghc-heap
./_build/stage0/src/libraries/ghci
./_build/stage0/src/libraries/os-string/
./_build/stage0/src/libraries/process/
./_build/stage0/src/libraries/semaphore-compat
./_build/stage0/src/libraries/time
./_build/stage0/src/libraries/unix/
./_build/stage0/src/libraries/Win32/
./_build/stage0/src/utils/ghc-pkg
./_build/stage0/src/utils/hsc2hs
./_build/stage0/src/utils/unlit
./_build/stage0/src/utils/genprimopcode/
./_build/stage0/src/utils/deriveConstants/

benchmarks: False
tests: False
allow-boot-library-installs: True

program-options
ghc-options: -fhide-source-paths -j

package *
library-vanilla: True
shared: False
executable-profiling: False
executable-dynamic: False
executable-static: False
ghc-options: -fhide-source-paths -j

package ghc-boot-th
flags: +bootstrap

-- package genprimopcode
-- flags: -build-tool-depends

allow-newer: ghc-boot-th
```

**Expected behavior**

It should build without failing.

**System information**
- Operating system: linux
- Fails with cabal-install 3.14.1.0 and HEAD. Works with cabal-install 3.12.1.0

**Additional context**

I've bisected and the commit introducing the issue is 8bdda9c0b6231f05eda3e06f677ec5b71bfbb7cf (cc @sheaf).

Contributor guide

Open the contributing guide

Research direction

Start by reviewing commit 8bdda9c0b6231f05eda3e06f677ec5b71bfbb7cf and the cabal.project-stage0 configuration described in the report. Reproduce the GHC stage0 build with cabal-install 3.14.1.0 or HEAD, compare it with 3.12.1.0, and verify that the build completes without invoking the wrong Happy environment.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.