在 Shake 函数“want”和“need”中使用“FilePattern”/通配符
Using `FilePattern`/wildcards in the Shake functions `want` and `need`
函数 want
和 need
都要求它们的输入类型为 FilePath
而不是 FilePattern
。我的输出和输入的文件名遵循不同的模式,输出是 _build/*checker.sh
,输入是 ./*.py
。因此,我宁愿做一个 want
的形式:
want ['_build/*checkers.sh']
比
want ['_build/dbchecker.sh', '_build/henk_checker.sh', ..., '_build/derp_checker.sh']
我尝试通过组合 getDirectoryFiles, action, need
来构建更复杂的 want
但这不起作用,因为 getDirectoryFiles
returns Action [FilePath]
而不是 FilePath
.
这个问题的正确解决方案是什么?
Action
,也就是 getDirectoryFiles
returns,好像是 Monad
,所以你可以使用 do
-notation:
do
paths <- getDirectoryFiles "" ["_build//*checkers.sh"]
want paths
或者只是
getDirectoryFiles "" ["_build//*checkers.sh"] >>= want
或
want =<< getDirectoryFiles "" ["_build//*checkers.sh"]
编辑: 根据 Neil Mitchell 的评论,want
需要替换为 need
。
Erik 关于 Action
是 monad 的评论已被证明非常有帮助。问题是动作已经存在于 Rules
monad 中——而不是相反(抱歉 Eric,不够具体)。下面的代码是我最终解决的。
import Development.Shake
import Development.Shake.Command
import Development.Shake.FilePath
import Development.Shake.Util
main :: IO ()
main = shakeArgs shakeOptions{shakeFiles="_build"} (do
action $ do dependencies <- getDirectoryFiles "" ["*checker.py"]
let scripts = map (\file -> "_build" </> file -<.> "sh") dependencies
need scripts)
函数 want
和 need
都要求它们的输入类型为 FilePath
而不是 FilePattern
。我的输出和输入的文件名遵循不同的模式,输出是 _build/*checker.sh
,输入是 ./*.py
。因此,我宁愿做一个 want
的形式:
want ['_build/*checkers.sh']
比
want ['_build/dbchecker.sh', '_build/henk_checker.sh', ..., '_build/derp_checker.sh']
我尝试通过组合 getDirectoryFiles, action, need
来构建更复杂的 want
但这不起作用,因为 getDirectoryFiles
returns Action [FilePath]
而不是 FilePath
.
这个问题的正确解决方案是什么?
Action
,也就是 getDirectoryFiles
returns,好像是 Monad
,所以你可以使用 do
-notation:
do
paths <- getDirectoryFiles "" ["_build//*checkers.sh"]
want paths
或者只是
getDirectoryFiles "" ["_build//*checkers.sh"] >>= want
或
want =<< getDirectoryFiles "" ["_build//*checkers.sh"]
编辑: 根据 Neil Mitchell 的评论,want
需要替换为 need
。
Erik 关于 Action
是 monad 的评论已被证明非常有帮助。问题是动作已经存在于 Rules
monad 中——而不是相反(抱歉 Eric,不够具体)。下面的代码是我最终解决的。
import Development.Shake
import Development.Shake.Command
import Development.Shake.FilePath
import Development.Shake.Util
main :: IO ()
main = shakeArgs shakeOptions{shakeFiles="_build"} (do
action $ do dependencies <- getDirectoryFiles "" ["*checker.py"]
let scripts = map (\file -> "_build" </> file -<.> "sh") dependencies
need scripts)