2015-04-21 10 views
1

我怎樣才能讓腳本在每次構建時執行一次「外部」動作?Shake是否適合爲人類用戶構建半自動化工具?

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 

回答

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! 
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!" 

這裏你使用普通的Haskell來運行Shake構建之後發射導彈。

+1

只要確保您不要提前開始執行「重新填充地球」操作。這可能會變...尷尬。 – Cactus

相關問題