2012-05-17 22 views
9

给定一个Haskell项目,是否有自动计算整个依赖项列表的方法?所有依赖的库以及已包含但不是必需的库。自动列出项目的依赖关系

+0

Cabal确实在运行'cabal init'时试图找出依赖关系。这是你想到的那种功能吗? –

+0

在什么阶段?我使用cabal init,并没有找出任何依赖关系。 –

+1

什么阶段?您已经编写了一些代码并准备好整理项目的阶段(创建.cabal文件)。一个足够新的cabal版本将读取模块并尝试推断依赖关系。 –

回答

8

正如我在评论中所说的,cabal-install已经通过模块查找(如GHCi)猜测包来做到这一点(我正在使用cabal-install 0.14.0)。它没有任何真正的智慧w.r.t.版本,所以它只是将版本设置为您安装的主要版本。

下面你可以看到我制作一个虚拟包,导入Data.Vector和cabal-install推断我使用的是矢量0.9。*。

[[email protected] blah]$ pwd 
/tmp/blah 
[[email protected] blah]$ cat Data/Blah.hs 
module Data.Blah where 

import Data.Vector 
[[email protected] blah]$ cabal init 
Package name? [default: blah] 
...SNIP... 
What does the package build: 
    1) Library 
    2) Executable 
Your choice? 1 
Include documentation on what each field means (y/n)? [default: n] 

Guessing dependencies...   <--- SEE, SEE! YAY! 

Generating LICENSE... 
Warning: unknown license type, you must put a copy in LICENSE yourself. 
Generating Setup.hs... 
Generating blah.cabal... 

You may want to edit the .cabal file and add a Description field. 
[[email protected] blah]$ cat blah.cabal 
-- Initial blah.cabal generated by cabal init. For further documentation, 
-- see http://haskell.org/cabal/users-guide/ 

name:    blah 
version:    0.1.0.0 
synopsis:   Sisponys 
-- description:   
-- license:    
license-file:  LICENSE 
author:    Me 
maintainer:   [email protected] 
-- copyright:   
-- category:    
build-type:   Simple 
cabal-version:  >=1.8 

library 
    exposed-modules:  Data.Blah 
    -- other-modules:  
    build-depends:  base ==4.5.*, vector ==0.9.* <-- SEE?? SEE! YIPPEE!! 
+0

我正在使用'cabal-install version 0.10.2'。这是与Haskell平台捆绑在一起的版本,所以我想这是最近的功能。 –

+0

@VladtheImpala我猜你需要最新的0.14.0版本。它包括各种'cabal init'改进。 –