Shake: how can I depend on dynamically generated source files?

For this directory structure:

.
├── frontend
│   ├── _build/          -- build dir, all files produced by shake, except for Frontend.elm, go here
│   ├── Build.hs         -- the build script
│   ├── build.sh         -- wrap Build.hs with `stack exec build -- $@`
│   ├── other files ...
│   ├── Frontend.elm     -- generated by a rule in Build.hs, `protoc  -I../proto --elm_out=. ../proto/frontend.proto`
│   ├── Index.elm        -- hand written source file
│   └── other elms ...   -- hand written source files
└── proto
    └── frontend.proto   -- protocol buffer message defination, hand written

The goal _build/index.jsdepends on all files .elm, including Frontend.elm, but is Frontend.elmgenerated by the rule in Build.hs, if I blindly do:

want ["_build/index.js"]
"_build/index.js" %> \out -> do
    elms <- filter (not . elmStuff)
            <$> (liftIO $ getDirectoryFilesIO "" ["//*.elm"])
    need elms
    blah blah

want ["Frontend.elm"]
"Frontend.elm" %> \_out -> do
    cmd ["protoc", "blah", "blah"]

build.sh clean would give me:

Lint checking error - value has changed since being depended upon:
  Key:  Frontend.elm
  Old:  File {mod=0x608CAAF7,size=0x53D,digest=NEQ}
  New:  File {mod=0x608CAB5B,size=0x53D,digest=NEQ}

Is there a way to tell shake to keep track of dynamically generated Frontend.elm, maybe first create it so that it does not change during the rest of the assembly, I tried priority 100 ("Frontend.elm" %> ...), it doesn’t work.

+4
source share
1 answer

You should probably:

  • Switch from getDirectoryFilesIOwhich does not track file system changes to getDirectoryFileswhat it does.
  • Frontend.elm, , , (, getDirectoryFiles).
  • () ​​ want ing Frontend.elm, , _build/index.js.

:

want ["_build/index.js"]
"_build/index.js" %> \out -> do
    need ["Frontend.elm"]
    elms <- filter (not . elmStuff)
            <$> getDirectoryFiles "" ["//*.elm"]
    need elms
    blah blah

"Frontend.elm" %> \_out -> do
    cmd ["protoc", "blah", "blah"]

Caveat lector: .

+2

Source: https://habr.com/ru/post/1682506/


All Articles