Stack/Cabal找不到快乐

Stack/Cabal cannot find happy

我正在尝试使用 Haskell 堆栈构建 the code from PCPH。但是,我收到有关 Cabal 未找到 happy 的错误。我 已经 安装了 alexhappy (它们在 /usr/bin 中)。

setup-Simple-Cabal-1.22.5.0-ghc-7.10.3: The program 'happy' is required but it
could not be found

--  While building package parconc-examples-0.4.3 using:

堆栈认为我的 PATH 是这样的:

$ stack exec bash
$ echo $PATH | tr : '\n'
/home/steshaw/Projects/parconc-examples/.stack-work/install/x86_64-linux/lts-4.2/7.10.3/bin
/home/steshaw/Projects/shelly/dotfiles/.stack/snapshots/x86_64-linux/lts-4.2/7.10.3/bin
/home/steshaw/Projects/shelly/dotfiles/.stack/programs/x86_64-linux/ghc-7.10.3/bin
/home/steshaw/.nix-profile/bin
/home/steshaw/.nix-profile/sbin
/usr/local/sbin
/usr/local/bin
/home/steshaw/Projects/shelly/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/snap/bin

这是 stack path 的输出:

stack-root: /home/steshaw/Projects/shelly/dotfiles/.stack
project-root: /home/steshaw/Projects/parconc-examples
config-location: /home/steshaw/Projects/parconc-examples/stack.yaml
bin-path: /home/steshaw/Projects/shelly/dotfiles/.stack/snapshots/x86_64-linux/lts-4.2/7.10.3/bin:/home/steshaw/Projects/shelly/dotfiles/.stack/programs/x86_64-linux/ghc-7.10.3/bin:/home/steshaw/.nix-profile/bin:/home/steshaw/.nix-profile/sbin:/usr/local/sbin:/usr/local/bin:/home/steshaw/Projects/shelly/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
programs: /home/steshaw/Projects/shelly/dotfiles/.stack/programs/x86_64-linux
compiler-exe: /home/steshaw/Projects/shelly/dotfiles/.stack/programs/x86_64-linux/ghc-7.10.3/bin/ghc
compiler-bin: /home/steshaw/Projects/shelly/dotfiles/.stack/programs/x86_64-linux/ghc-7.10.3/bin
local-bin: /home/steshaw/.local/bin
extra-include-dirs: 
extra-library-dirs: 
snapshot-pkg-db: /home/steshaw/Projects/shelly/dotfiles/.stack/snapshots/x86_64-linux/lts-4.2/7.10.3/pkgdb
local-pkg-db: /home/steshaw/Projects/parconc-examples/.stack-work/install/x86_64-linux/lts-4.2/7.10.3/pkgdb
global-pkg-db: /home/steshaw/Projects/shelly/dotfiles/.stack/programs/x86_64-linux/ghc-7.10.3/lib/ghc-7.10.3/package.conf.d
ghc-package-path: /home/steshaw/Projects/parconc-examples/.stack-work/install/x86_64-linux/lts-4.2/7.10.3/pkgdb:/home/steshaw/Projects/shelly/dotfiles/.stack/snapshots/x86_64-linux/lts-4.2/7.10.3/pkgdb:/home/steshaw/Projects/shelly/dotfiles/.stack/programs/x86_64-linux/ghc-7.10.3/lib/ghc-7.10.3/package.conf.d
snapshot-install-root: /home/steshaw/Projects/shelly/dotfiles/.stack/snapshots/x86_64-linux/lts-4.2/7.10.3
local-install-root: /home/steshaw/Projects/parconc-examples/.stack-work/install/x86_64-linux/lts-4.2/7.10.3
snapshot-doc-root: /home/steshaw/Projects/shelly/dotfiles/.stack/snapshots/x86_64-linux/lts-4.2/7.10.3/doc
local-doc-root: /home/steshaw/Projects/parconc-examples/.stack-work/install/x86_64-linux/lts-4.2/7.10.3/doc
dist-dir: .stack-work/dist/x86_64-linux/Cabal-1.22.5.0
local-hpc-root: /home/steshaw/Projects/parconc-examples/.stack-work/install/x86_64-linux/lts-4.2/7.10.3/hpc
local-bin-path: /home/steshaw/.local/bin
ghc-paths: /home/steshaw/Projects/shelly/dotfiles/.stack/programs/x86_64-linux

这是堆栈在我的路径上找到的 happy 版本:

$ stack exec -- happy -V
Happy Version 1.19.5 Copyright (c) 1993-1996 Andy Gill, Simon Marlow (c) 1997-2005 Simon Marlow

Happy is a Yacc for Haskell, and comes with ABSOLUTELY NO WARRANTY.
This program is free software; you can redistribute it and/or modify
it under the terms given in the file 'LICENSE' distributed with
the Happy sources.

我正在使用 Ubuntu 16.04.1 LTS (x86_64)。

尝试两件事:

  1. 使用项目的解析器通过堆栈安装 happy:

    stack install happy --resolver lts-4.2
    

当我使用解析器 lts-4.2 构建 parconc-examples 时,我发现它 正在使用 lts-4.2 快照目录中的 happy 二进制文件,尽管 我把它安装在我的 PATH 的其他地方。

  1. 使用这个 Setup.hs 程序:

    import Distribution.Simple
    import System.Environment
    
    main = do
      args <- getArgs
      let args' = if elem "configure" args
                    then args ++ [ "--with-happy=/usr/bin/happy" ]
                    else args
      defaultMainWithArgs args'
    

还要确保将 parconc-examples.cabal 中的 build-type: 更改为 Custom。完全删除 .stack-work 目录以确保使用新的安装程序重建所有内容。