如何避免在这个cabal文件中重新编译? [英] How to avoid recompiling in this cabal file?

查看:138
本文介绍了如何避免在这个cabal文件中重新编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究这个Haskell项目,并且我有一个cabal文件。现在,我的项目被组织为一个实现简单解释器的库。我也有一个非常短的主文件,需要将其构建到可执行文件中以调用库。我想要做的是:
$ b $ 1)编译库并展示一些模块

2)编译可执行文件



我有一个可以工作的cabal文件,似乎是这样做的。问题是当它编译可执行文件时,它会重新编译已经在步骤(1)中编译过的所有模块。我不明白为什么它会这样做 - 是否有任何方法可以阻止它,创建两个单独的cabal文件?



我并不想创建两个独立的cabal文件,因为cabal似乎不喜欢将cabal文件放在同一个目录中,而且我也不想为第二步设置一个单独的项目目录,因为它基本上只是编译一个单个文件。

  cabal-version:> = 1.6 
build-type:Simple
name: HaSC
版本:0.2.3
许可证:OtherLicense
类别:语言
作者:Chris B
维护者:Chris B
版权所有:Chris B 2010 - 2011
简介:(HA)skell(S)ound(C)hange applier(HaSC)library
描述:HaSC实现了一种用于将声音变化应用于单词的小语言
homepage:http:/ /www.chrisdb.me.uk/redmine/projects/h askell-sound-change
稳定性:Alpha
data-files:doc / HaSCDoc.pdf
许可证文件:许可证

图书馆
build-depends :
base> = 4.3,
containers> = 0.3,
parsec> = 3,
并行> = 3.1,
deepseq> = 1.1 ,
mtl> = 1.1,
变形金刚> = 0.2,
文字> = 0.10,
text-icu> = 0.6.3,
漂亮> = 1,
目录> = 1.1,
filepath> = 1.2
hs-source-dirs:src
exposed-modules:HaSC.IO.Disk,
HaSC.IO.Memory,
HaSC.Exec
other-modules:HaSC.AST,
HaSC.IO,
HaSC.IdentMap,
HaSC。解析,
HaSC.Regex,
HaSC.Representation,
HaSC.Transformatio ns,
HaSC.Search,
HaSC.State

可执行文件HaSC
GHC-Options:-rtsopts
hs-source-dirs:src
main-is:Main.hs


解决方案

Build-Depends 中添加库,以便可执行文件依赖库。



但是:您还必须将可执行文件(以及可执行文件特有的任何其他源文件)的 Main.hs 移动到不同的子目录,并指定一个不同的 Hs-Source-Dirs ,这样它就不会将文件夹模块放在同一个文件夹中。



<$ p $ $ h $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $

为此,您需要指定 Cabal-Version> = 1.8 。详情请参阅 Cabal ticket#89


I've been working on this Haskell project, and I have a cabal file for it. Now, my project is structured as a library that implements a simple interpreter. I also have a very short Main file which needs to be build into an executable to call the library. What I want to do is:

1) compile the library and expose some of the modules

2) compile the executable

I have a cabal file that works and seems to do this. The problem is that when it compiles the executable it recompiles all the modules which have already been compiled in step (1). I don't quite understand why it does this - is there any way to stop it, short of creating two separate cabal files?

I don't really want to create two separate cabal files, because cabal doesn't seem to like having both the cabal files in the same directory, and I don't really want to set up a separate project directory for the second step, since it basically just amounts to compiling a single file.

cabal-version:      >= 1.6
build-type:         Simple
name:               HaSC
version:            0.2.3
license:            OtherLicense
category:           Language
author:             Chris B
maintainer:         Chris B
copyright:          Chris B 2010 - 2011
synopsis:           (HA)skell (S)ound (C)hange applier (HaSC) library
description:        HaSC implements a little language for applying sound changes to words
homepage:           http://www.chrisdb.me.uk/redmine/projects/haskell-sound-change
stability:          Alpha
data-files:         doc/HaSCDoc.pdf
license-file:       LICENSE

library
    build-depends:
        base >= 4.3,
        containers >= 0.3,
        parsec >= 3,
        parallel >= 3.1,
        deepseq >= 1.1,
        mtl >= 1.1, 
        transformers >= 0.2,
        text >= 0.10,
        text-icu >= 0.6.3,
        pretty >= 1,
        directory >= 1.1,
        filepath >= 1.2
    hs-source-dirs:  src
    exposed-modules: HaSC.IO.Disk,
                     HaSC.IO.Memory,
                     HaSC.Exec
    other-modules:   HaSC.AST,
                     HaSC.IO,
                     HaSC.IdentMap,
                     HaSC.Parse,
                     HaSC.Regex,
                     HaSC.Representation,                     
                     HaSC.Transformations,
                     HaSC.Search,
                     HaSC.State

executable HaSC
    GHC-Options: -rtsopts
    hs-source-dirs:  src
    main-is:         Main.hs    

解决方案

In your executable section, add the library in Build-Depends so that the executable depends on the library.

There's a small gotcha, though: You also have to move the Main.hs of the executable (and any other source files specific to the executable) to a different subdirectory and specify a different Hs-Source-Dirs so that it doesn't pick up the library modules by being in the same folder.

executable HaSC
    Build-Depends: HaSC
    Main-Is: Main.hs
    Hs-Source-Dirs: foo -- Directory you moved Main.hs to

For this to work, you will need to specify Cabal-Version >= 1.8. See Cabal ticket #89 for the details.

这篇关于如何避免在这个cabal文件中重新编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆