繁体   English   中英

为什么“cabal init”打破了“ghc-mod check”?

[英]Why does “cabal init” break “ghc-mod check”?

ghc-mod只在一个haskell源文件的目录下工作,但如果我在该目录(/ tmp / test)中运行“cabal init”,我会收到以下错误:

(p1)dave@peach:/tmp/test$ !ghc
ghc-mod check Main.hs 
ghc-mod: /tmp/test/dist/setup-config: hGetContents: invalid argument (invalid byte sequence)

这里出了什么问题?

我在64位ubuntu 14.04计算机上运行ghc-mod 5.2.11和cabal 1.21.1.0。 LANG环境变量设置为en_US.UTF-8(我看到对其他一些问题的回答,这些问题表明LANG设置在这里可能很重要)。 我试过运行cabal版本1.16.0,但它没有任何区别。

这是一份显示更多细节的成绩单:

(p1)dave@peach:/tmp/test$ ls -la
total 80
drwxrwxr-x  2 dave dave  4096 Dec  4 07:07 .
drwxrwxrwt 35 root root 69632 Dec  4 07:06 ..
-rw-rw-r--  1 dave dave   143 Dec  4 07:04 Main.hs

(p1)dave@peach:/tmp/test$ set | grep LANG
GDM_LANG=en_US
LANG=en_US.UTF-8
LANGUAGE=en_US

(p1)dave@peach:/tmp/test$ ghc-mod version
ghc-mod version 5.2.1.1 compiled by GHC 7.6.3

(p1)dave@peach:/tmp/test$ cabal -V
cabal-install version 1.21.1.0
using version 1.21.1.0 of the Cabal library 

(p1)dave@peach:/tmp/test$ ghc-mod check Main.hs 
Main.hs:7:1:Warning: Top-level binding with no type signature:  haqify :: [Char] -> [Char]

(p1)dave@peach:/tmp/test$ cabal init
Package name? [default: test] 
Package version? [default: 0.1.0.0] 
Please choose a license:
 * 1) (none)
   2) GPL-2
   3) GPL-3
   4) LGPL-2.1
   5) LGPL-3
   6) AGPL-3
   7) BSD2
   8) BSD3
   9) MIT
  10) ISC
  11) MPL-2.0
  12) Apache-2.0
  13) PublicDomain
  14) AllRightsReserved
  15) Other (specify)
Your choice? [default: (none)] 2
Author name? [default: XXXXXXXXXXXX] 
Maintainer email? [default: XXXXXXXXXXXXXXXXXXXXXX] 
Project homepage URL? 
Project synopsis? 
Project category:
 * 1) (none)
   2) Codec
   3) Concurrency
   4) Control
   5) Data
   6) Database
   7) Development
   8) Distribution
   9) Game
  10) Graphics
  11) Language
  12) Math
  13) Network
  14) Sound
  15) System
  16) Testing
  17) Text
  18) Web
  19) Other (specify)
Your choice? [default: (none)] 
What does the package build:
   1) Library
   2) Executable
Your choice? 2
What is the main module of the executable:
 * 1) Main.hs
   2) Other (specify)
Your choice? [default: Main.hs] 
What base language is the package written in:
 * 1) Haskell2010
   2) Haskell98
   3) Other (specify)
Your choice? [default: Haskell2010] 
Include documentation on what each field means (y/n)? [default: n] 
Source directory:
 * 1) (none)
   2) src
   3) Other (specify)
Your choice? [default: (none)] 

Guessing dependencies...

Generating LICENSE...
Generating Setup.hs...
Generating test.cabal...

Warning: no synopsis given. You should edit the .cabal file and add one.
You may want to edit the .cabal file and add a Description field.

(p1)dave@peach:/tmp/test$ !ghc
ghc-mod check Main.hs 
ghc-mod: /tmp/test/dist/setup-config: hGetContents: invalid argument (invalid byte sequence)
(p1)dave@peach:/tmp/test$ 

ghc-mod不适用于GHC <7.10和Cabal-1.22。

如果您仍然使用GHC 7.8.3或7.8.4,则可能需要暂停更新cabal或cabal-install。

简而言之:

  1. 使用沙箱进行项目;
  2. 向您的PATH变量添加沙箱所在文件夹的本地路径;
  3. 在那里安装Cabal version <= 1.20.0.6 (版本1.20.0.6是最新版本,不会破坏ghc-mod );
  4. 向您的PATH变量添加沙箱所在文件夹的本地路径;
  5. 安装到您的沙箱所需的包( ghc-mod等)。

转到项目的根文件夹并创建一个沙箱:

cd ~/tmp/test       #go to you project's root directory
cabal sandbox init  #create a sandbox

每次从当前目录运行cabal sandbox init ,它都会在给定目录中创建一个.cabal-sandbox文件夹。 如果你将ghc-mod安装到沙盒中(即隔离),它仍然会使用沙盒版本的cabalcabal-install来安装它,因为它在你的PATH 要解决此问题,请在~/.bash_profile文件中添加以下行:

export PATH="./.cabal-sandbox/bin:$PATH"

路径开头的点表示您要在当前目录中搜索名为.cabal-sandbox的文件夹,其中包含名为bin子文件夹,其中安装了沙.cabal-sandbox 如果在包含沙箱的文件夹中运行命令,系统将从适当的沙箱运行可执行文件。 如果文件夹不包含沙箱,则它将使用*/.cabal/bin目录的常用路径。

确保您的沙箱路径位于PATH变量中*/.cabal/bin常用路径之前。 您可以使用终端$PATH命令查看路径的顺序。

使用终端source ~/.bash_profile命令重新加载~/.bash_profile文件,或者关闭并重新打开终端。

接下来安装Cabal version <= 1.20.0.6 ,它不会破坏ghc-mod

cabal install cabal-install-1.20.0.6  #install the latest cabal supported by ghc-mod

使用终端source ~/.bash_profile命令再次重新加载~/.bash_profile文件,或者关闭并重新打开终端。

从沙箱文件夹中运行cabal --version 它应该表明您使用的是cabal-install version 1.20.0.6version 1.20.0.3 of the Cabal library cabal-install version 1.20.0.6 version 1.20.0.3 of the Cabal library 从没有沙箱的文件夹运行cabal --version ,看看全局,你仍然使用当前版本的cabal-installCabal library

返回项目的根文件夹并安装到您需要的沙箱包:

cd ~/tmp/test                 #go to you project's root directory
cabal install ghc-mod-5.2.1.2 #explicitly indicate version of ghc-mod you want to install, otherwise cabal will try to install an ancient version 0.3.0

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM