haskellshake

In Haskell Shake, how can I want a file pattern?


I have a directory of xml files in a source directory that I want to turn into a directory of html files in a destination directory. It seems I can use getDirectoryFiles to get files from a directory, but that is an Action, and want needs not an Action [FilePath] but just a [FilePath]. How can I do something like want ["dest/*.html"] in Shake?


Solution

  • If I understand you correctly, you can do like this.

    First of all, write a rule that creates the html file from xml.

    main = shakeArgs shakeOptions $ do
        "dest/*.html" %> \out -> do
            let src = "source" </> dropDirectory1 out -<.> "xml"
            -- todo: generate out (HTML) from src (XML)
    

    Then you can write a rule by action that will be run in every build execution.

    main = shakeArgs shakeOptions $ do
        action $ do
            srcs <- getDirectoryFiles "source" ["*.xml"]
            need ["dest" </> src -<.> "html" | src <- srcs]
    
        "dest/*.html" %> \out -> do
            let src = "source" </> dropDirectory1 out -<.> "xml"
            -- todo: translate HTML(out) from XML(src)
    

    For your information, want defined like: want xs = action $ need xs.