4

给定这样的目录结构:

.
├── 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

目标_build/index.js取决于所有.elm文件,包括Frontend.elm,但如果我盲目地这样做,Frontend.elm则由 中的规则生成:Build.hs

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会给我:

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}

有没有办法告诉shake注意动态生成的Frontend.elm,也许先构建它,这样它在构建的其余部分就不会改变,我试过了priority 100 ("Frontend.elm" %> ...),不起作用。

4

1 回答 1

2

You should probably:

  1. Switch from getDirectoryFilesIO, which does not track changes to the file system, to getDirectoryFiles, which does.
  2. Declare your dependence on Frontend.elm, which you know you need even if it does not exist in the filesystem yet (hence might not be visible to getDirectoryFiles).
  3. (Optional) Don't bother wanting Frontend.elm, since you only wanted it as a hack to enable _build/index.js.

With these changes, it would look like this:

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: I have not tested this solution.

于 2017-07-28T17:41:20.017 回答