1

如何使每次构建时填充的脚本执行“外部”操作?

import Development.Shake

main = shakeArgs shakeOptions $ do
    want [".finished"]
    ".finished" %> \out -> do
      liftIO $ putStrLn "You sure?" >> getLine >> putStrLn "Missiles fired!"
$ runhaskell Main.hs
You sure?
no
Missiles fired!
Error when running Shake build system:
* .finished
Error, rule ".finished" failed to build file:
  .finished
4

2 回答 2

1

对代码的最小修复是phony像@Cactus 建议的那样使用。另一种方法是action直接使用:

import Development.Shake
import Control.Monad (unless)

main = shakeArgs shakeOptions $ do
    action $ do
        ok <- fmap (== "yes") $ liftIO $ putStrLn "You sure?" >> getLine
        unless ok $ fail "Your commitment to the Great War is lacking!"
        liftIO $ putStrLn "Missiles fired!"

如果不是在构建过程中的任何时候运行发射导弹,而是实际上希望在最后运行它(在您构建导弹并储存在锡罐上之后),您可以编写:

main = do
    shakeArgs shakeOptions $ do
        ...normal build rules go here...
    ok <- fmap (== "yes") $ putStrLn "You sure?" >> getLine
    unless ok $ fail "Your commitment to the Great War is lacking!"
    putStrLn "Missiles fired!"

在运行 Shake 构建之后,您在这里使用普通的 Haskell 来发射导弹。

于 2015-04-22T06:45:00.210 回答
1

由于您的操作不会生成文件,因此需要将其标记为phony规则:

import Development.Shake
import Control.Monad (unless)

main = shakeArgs shakeOptions $ do
    want [".finished"]
    phony ".finished" $ do
        ok <- fmap (== "yes") $ liftIO $ putStrLn "You sure?" >> getLine
        unless ok $ fail "Your commitment to the Great War is lacking!"
        liftIO $ putStrLn "Missiles fired!"

示例会话:

$ runhaskell shake-phony.hs
You sure?
yes
Missiles fired!
Build completed in 0:29m

$ runhaskell shake-phony.hs
You sure?
no
Error when running Shake build system:
* .finished
Your commitment to the Great War is lacking!
于 2015-04-22T04:14:17.690 回答