0

I am using Shake to build lilypond files, which are then being put into a webpage. I tried to model my Build.hs after the first example in the manual:

import Development.Shake
import Development.Shake.Command
import Development.Shake.FilePath
import Development.Shake.Util

dest = "www/static"

main :: IO ()
main = shakeArgs shakeOptions{shakeFiles="_build"} $ do
  want ["www/index.html"]

  phony "clean" $ do
    putNormal "Cleaning files"
    removeFilesAfter dest ["//*"]

  "www/index.html" %> \out -> do
    fs <- getDirectoryFiles "src/lilypond" ["*.ly"]
    let pdfs = ["www/static" </> (takeBaseName sourceFile) -<.> "pdf" | sourceFile <- fs]
    need pdfs

    cmd_ "cp" "src/www/index.html" "www/index.html"

  dest <> "//*.pdf" %> \outp -> do
    let c = "src/lilypond" </> (dropDirectory1 . dropDirectory1 $ outp -<.> "ly")
    let o = dropExtension outp
    cmd_ "lilypond" "-o" [o] [c]

The intended behaviour is "to build the index.html file, all PDFs should be generated to www/static from respective src/lilypond/*.ly files". This works for a clean build, but editing a source .ly files does not trigger a rebuild and I can't figure out why. (UPDATE: editing src/www/index.html also does not trigger a rebuild)

Things I've tried:

  • Building a single PDF via command like shake-build www/static/muppets.pdf. Same behaviour.
  • Generating a --profile. Nothing jumps out to me here.
  • Verbose output. Not sure what to look for here, so suspect maybe the PDF rule isn't actually depending on the .ly file? Saw depends = [] in output, would have expected non empty.
  • Explicit need [c] in the PDF rule.

I feel like there is a basic concept here I've missed :/

Full project here.

Xavier Shay
  • 4,067
  • 1
  • 30
  • 54
  • I think you are missing a call to `need [c]` just before `cmd_ "lilypond" ...`. That will cause it to add the necessary dependency - as a general rule of thumb, before calling `cmd`, you call `need` on all the things it will use. – Neil Mitchell Aug 11 '19 at 08:21
  • 1
    could have swore I tried that, but nope apparently not. Works, thank you! – Xavier Shay Aug 17 '19 at 05:54
  • Great to hear, I've promoted it to an answer so we can Q/A it out properly and for those who come here in future. – Neil Mitchell Aug 19 '19 at 06:33
  • 1
    thanks for all the work you do for the community Neil Accepted your answer. – Xavier Shay Aug 20 '19 at 22:31

1 Answers1

1

You are missing a call to need [c] just before cmd_ "lilypond" .... That will cause it to add the necessary dependency - as a general rule of thumb, before calling cmd, you call need on all the things it will use.

Neil Mitchell
  • 9,090
  • 1
  • 27
  • 85