如何在cabal/stack中添加CPP定义?
我期待在以下模块:https://hackage.haskell.org/package/boxes-0.1.4/docs/src/Text-PrettyPrint-Boxes.html如何在cabal/stack中添加CPP定义?
其中有内容:
module Text.PrettyPrint.Boxes
(-- * Constructing boxes
#ifdef TESTING
Box(Box, content)
#else
Box
#endif
我怎么可以启用/定义TESTING
值 - 用于开发目的?理想情况下,我希望在GHCi会话中构建/启用此功能。
我必须纠正自己 - 我给出的评论完全和完全错误。
> git clone git://github.com/treeowl/boxes.git
> cd boxes
> stack init
> stack ghci --ghc-options=-DTESTING
split-0.2.3.2: using precompiled package
boxes-0.1.4: configure (lib)
Configuring boxes-0.1.4...
boxes-0.1.4: initial-build-steps (lib)
Completed 2 action(s).
Configuring GHCi with the following packages: boxes
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from ...
[1 of 1] Compiling Text.PrettyPrint.Boxes (.../boxes/Text/PrettyPrint/Boxes.hs, interpreted)
Ok, modules loaded: Text.PrettyPrint.Boxes.
Loaded GHCi configuration from /tmp/ghci28386/ghci-script
*Text.PrettyPrint.Boxes Text.PrettyPrint.Boxes> :t content
content :: Box -> Content
工作正常。
这似乎只在'boxes'项目上调用stack ghci时才起作用,而不是通过cabal将其作为依赖项包含在内。 –
你可以发送一个pull请求到box并提供一个cabal标志,并在此期间使用你的github回购,堆栈内置了使用回购作为源的选项;对于cabal我有一段时间没有使用它,所以我不知道这是否是一个选项。 – epsilonhalbe
如果你需要'内容'功能的东西,而不是测试目的 - 我会问维护者有关隐藏所述功能的意图!有很多方便的东西,但使用时增加一些风险或其他。 – epsilonhalbe
如果您调用'stack test',则标志会自动设置 - 现在没有cabal标志来启用此CPP标志。 – epsilonhalbe