摇:我如何依赖动态生成的源文件?

时间:2017-07-28 15:14:42

标签: haskell shake-build-system

给定这样的目录结构:

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

有没有办法告诉摇动注意动态生成的Frontend.elm,可能先构建它,以便它在构建的其余部分没有改变,我试过priority 100 ("Frontend.elm" %> ...),不起作用。

1 个答案:

答案 0 :(得分:2)

你可能应该:

  1. 从不跟踪文件系统更改的getDirectoryFilesIO切换到getDirectoryFiles,这样做。
  2. 声明您对Frontend.elm的依赖,即使它在文件系统中不存在,您也知道它需要(因此getDirectoryFiles可能不可见)。
  3. (可选)请勿打扰want Frontend.elm,因为您只想将其作为启用_build/index.js的黑客攻击。
  4. 通过这些更改,它看起来像这样:

    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"]
    

    警告:我还没有测试过这个解决方案。