Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive rule when copying only some files #767

Closed
yogsototh opened this issue Jun 23, 2020 · 2 comments
Closed

Recursive rule when copying only some files #767

yogsototh opened this issue Jun 23, 2020 · 2 comments

Comments

@yogsototh
Copy link

yogsototh commented Jun 23, 2020

Edit: I tried with 0.19 and it seems I have the error message everytime. I am pretty sure I misused shake :). Still there might be some underlying issue. So I'll let you close it.

While I was trying to use shake to generate a static website I stumble upon this strange behavior.
For me it looks like a bug.
So the here is a self-contained way to reproduce the problem:

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}

import           Protolude

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

main :: IO ()
main = shakeArgs shOpts buildRules
  where
    shOpts =
      shakeOptions
      { shakeVerbosity  = Chatty
      , shakeLintInside = ["\\"]
      }


siteDir :: FilePath
siteDir  = "_site"

optimDir :: FilePath
optimDir = "_optim"


build :: FilePath -> FilePath
build = (</>) siteDir

copy :: FilePath -> Action ()
copy out = do
  let src = "src" </> (dropDirectory1 out)
  copyFileChanged src out

cleanRule :: Rules ()
cleanRule =
  phony "clean" $ do
    putInfo "Cleaning files in _site and _optim"
    forM_ [siteDir,optimDir] $ flip removeFilesAfter ["//*"]

buildRules :: Rules ()
buildRules = do
  cleanRule
  build "//*" %> copy

And my build.sh file:

#!/bin/sh
mkdir -p _shake
ghc --make Shakefile.hs -rtsopts -threaded -with-rtsopts=-I0 -outputdir=_shake -o _shake/build && _shake/build "$@"

And then I try to execute

> ./build.sh clean
[1 of 1] Compiling Main             ( Shakefile.hs, _shake/Main.o )
Linking _shake/build ...
# clean
Cleaning files in _site and _optim
Will remove //* from _site
Will remove //* from _optim
Build completed in 0.00s

work as expected

> ./build.sh _site/posts/0010-Haskell-Now/index.org
# _site/posts/0010-Haskell-Now/index.org
Copying from src/posts/0010-Haskell-Now/index.org to _site/posts/0010-Haskell-Now/index.org
Build completed in 0.00s

also copy as expected.
But when trying on .hs files or .jpg files:

> ./build.sh _site/posts/0010-Haskell-Now/list.hs
# _site/posts/0010-Haskell-Now/list.hs
# src/posts/0010-Haskell-Now/list.hs
Error when running Shake build system:
  at want, called at src/Development/Shake/Internal/Args.hs:83:69 in shake-0.18.5-8T3hsb7Jhgk1bvj5gpap6X:Development.Shake.Internal.Args
* Depends on: _site/posts/0010-Haskell-Now/list.hs
  at copyFileChanged, called at Shakefile.hs:34:3 in main:Main
  at need, called at src/Development/Shake/Internal/Derived.hs:104:5 in shake-0.18.5-8T3hsb7Jhgk1bvj5gpap6X:Development.Shake.Internal.Derived
* Depends on: src/posts/0010-Haskell-Now/list.hs
  at copyFileChanged, called at Shakefile.hs:34:3 in main:Main
  at need, called at src/Development/Shake/Internal/Derived.hs:104:5 in shake-0.18.5-8T3hsb7Jhgk1bvj5gpap6X:Development.Shake.Internal.Derived
* Depends on: src/posts/0010-Haskell-Now/list.hs
* Raised the exception:
Build system error - recursion detected:
  Key type:   FileQ
  Key value:  src/posts/0010-Haskell-Now/list.hs
Rules may not be recursive

Edits:

  • the same problem occurs if I use copyFile' instead of copyFileChanged.
  • if that can help my shell.nix:
{ pkgs ? import (fetchTarball https://github.com/NixOS/nixpkgs/archive/20.03.tar.gz) {} }:
let
  pkgs1909 = import (fetchTarball https://github.com/NixOS/nixpkgs/archive/19.09.tar.gz) {};
  haskellDeps = ps : with ps; [
    shake
    pandoc
    data-default
    protolude
    pkgs1909.haskellPackages.sws
    stache
  ];
  ghc = pkgs.haskellPackages.ghcWithPackages haskellDeps;
in
pkgs.mkShell {
    buildInputs = with pkgs;
      [ cacert
        coreutils
        html-xml-utils
        zsh
        perl
        perlPackages.URI
        minify
        niv
        ghc
        git
        direnv
        haskellPackages.shake
      ];
  }
@ndmitchell
Copy link
Owner

Ah, I know what the issue is! You are using // style escapes. The issue with them is that:

`"_site" </> "//*"

Gives //* because </> is documented to return the second component if it is already absolute. You can fix it by moving to the new-style file patterns, writing:

`"_site" </> "**"

Which means the same thing. The plan is to slowly deprecate // - I should follow up on that plan as its a horrible default because its so easy to get wrong with </>.

@yogsototh
Copy link
Author

Ah thanks a lot! Yes, I somehow made it work with more complex rules but after a few changes, I got that message again.

Also thanks for all your hard work! I love to use hlint, hoogle and ghcid, and I'm starting to love to use shake now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants