`GHC.Paths。*`的来源是从哪里来的?

时间:2016-06-29 10:00:00

标签: haskell haskell-stack

我正在运行stack版本1.1.2 x86_64 hpack-0.14.1

$ stack exec which ghc
Run from outside a project, using implicit global project config
Using resolver: lts-5.10 from implicit global project's config file: /home/wisut/.stack/global-project/stack.yaml
/home/wisut/.stack/programs/x86_64-linux/ghc-7.10.3/bin/ghc

但是当stack ghciGHC.Paths一起使用时,它会返回错误的路径

$ stack ghci
Run from outside a project, using implicit global project config
Using resolver: lts-5.10 from implicit global project's config file: /home/wisut/.stack/global-project/stack.yaml
Error parsing targets: The specified targets matched no packages. Perhaps you need to run 'stack init'?
Warning: build failed, but optimistically launching GHCi anyway
Configuring GHCi with the following packages: 
GHCi, version 7.10.3: http://www.haskell.org/ghc/  :? for help
Ok, modules loaded: none.
Prelude> GHC.Paths.ghc
"/usr/bin/ghc-7.10.3"

我正在运行带有ghc 8.0.1的Arch linux,因此外面没有ghc-7可用stack

[wisut@earth ~]$ which ghc
/usr/bin/ghc
[wisut@earth ~]$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.0.1
[wisut@earth ~]$ ls -al /usr/bin/ghc
lrwxrwxrwx 1 root root 9 May 24 18:28 /usr/bin/ghc -> ghc-8.0.1

查看GHC.Paths源代码,我不知道该值的来源。它是ENV变量吗?

{-# LANGUAGE CPP #-}

module GHC.Paths (
        ghc, ghc_pkg, libdir, docdir
  ) where

libdir, docdir, ghc, ghc_pkg :: FilePath

libdir  = GHC_PATHS_LIBDIR
docdir  = GHC_PATHS_DOCDIR

ghc     = GHC_PATHS_GHC
ghc_pkg = GHC_PATHS_GHC_PKG

正在运行stack exec env没有看到任何内容。

$ stack exec env | grep -i ghc
Run from outside a project, using implicit global project config
GHC_PACKAGE_PATH=/home/wisut/.stack/global-project/.stack-work/installx86_64-linux/lts-5.10/7.10.3/pkgdb:/home/wisut/.stack/snapshots/x86_64-linux/lts-5.10/7.10.3/pkgdb:/home/wisut/.stack/programs/x86_64-linux/ghc-7.10.3/lib/ghc-7.10.3/package.conf.d
PATH=/home/wisut/.stack/global-project/.stack-work/install/x86_64-linux/lts-5.10/7.10.3/bin:/home/wisut/.stack/snapshots/x86_64-linux/lts-5.10/7.10.3/bin:/home/wisut/.stack/programs/x86_64-linux/ghc-7.10.3/bin:/home/wisut/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl

如何修复错误的值?如何配置stack以使GHC.Paths返回正确的内容?

UPD 我尝试使用stack运行--no-system-ghc并且没有任何区别。 我尝试删除~/.cabal~/.stack个文件夹。我不得不做stack setup,并且在stack重新安装编译器之后它没有给我错误的路径,但它并没有给我任何 path,该命令的输出现在为空。 Setup.hs中的任何一个都没有什么特别的。

1 个答案:

答案 0 :(得分:1)

您几乎是对的,GHC_变量是来自custom Setup.hs的CPP定义:

let buildinfo = emptyBuildInfo{
         cppOptions = ["-DGHC_PATHS_GHC_PKG=" ++ show c_ghc_pkg,
                       "-DGHC_PATHS_GHC=" ++ show c_ghc,
                       "-DGHC_PATHS_LIBDIR=" ++ show libdir,
                       "-DGHC_PATHS_DOCDIR=" ++ show docdir ]
       }

关于错误路径的问题,请尝试运行stack --no-system-ghc ghci。如果它仍然显示GHC路径的"/usr/bin/ghc-7.10.3",那么当您为GHC-7.10.3编译ghc-paths时,我怀疑你 GHC }和stack没有重建的东西相当不错,ghc-paths的旧版本仍然存在。我不知道在快照中重建包的方法,除了whiping ~/.stack并重新开始之外;这可能是一个好主意。如果你改变了全球GHC的东西。

存在相关问题:Stop using system-ghc silently