我正在研究调用Web服务的haskell应用程序。我希望在使用stack build
进行构建时,应用程序会以实际生产服务器的URL为目标,但在使用stack repl
进行调试时,应用程序会以测试服务器的URL为目标。
我想这可以通过条件编译来实现,但是如何配置堆栈以将-DDEBUG=1
等选项传递给GHCi而不是GHC?
更一般地说,许多工具(Visual Studio,Xcode ...)支持项目的多个构建配置。是否有堆叠或阴谋等同物?
答案 0 :(得分:3)
One way to do this is to check at runtime if System.Environment.getProgName
is ghc
. This is not necessarily a reliable check, because the executable could in some cases be called something else. It will be ghc
for stack installed executables, but for system installed ghcs it might very well be ghc-8.0.1
or something. So, this approach is not all that reliable.
A better approach has occurred to me, which is to add a .ghci
file, which contains commands for ghci to run on startup. I haven't tested this, but I think it would work to put :set -DDEBUG=1
in .ghci
in your project root. Will also need to tweak its permissions with chmod go-w .ghci
.