openshake
openshake copied to clipboard
"ls" only matches files relative to the current directory
If you use ls
in a rule, it won't pick up paths outside of the current directory (unless you use "..").
This seems to be a bug from the Glob
library. E.g., try this
$ cd ~/tmp
$ touch aaa
$ ghci
> import System.FilePath.Glob
> globDir1 (compile "/home/me/tmp/aaa") "" -- use your home dir
This should find the given file, but doesn't.
The code sample you give shouldn't work since I think the arguments to globDir1 are the wrong way around. Try this:
globDir1 (compile "*") "/Users/myusername"
It works as expected.
Can you give me an example of how ls fails?
Well, the Glob
library itself may not be at fault, but one could argue that openshake is. The use case is the following:
When I compile a file with GHC it goes on to look through a number of search paths to find source files and dependencies, etc. These paths are usually outside the current project directory. I want to properly model all of these dependencies, because if the contents of these directories change it may affect my project.
The way globDir
is currently used inside openshake I am not able to specify a dependency on a file where I know the absolute path. I can only refer to it by computing the right amount of "../".
OK now I understand.
So you expect that globDir1 ((compile dir) fp) should return getDirectoryContents dir for any fp. This does indeed seem like reasonable behaviour for the glob package.
Well, yes, although even more general. The fp
argument should really only be used to resolve relative patterns (e.g., foo*
), but absolute filepath patterns should be allowed, too, i.e., globDir1 (compile (dir </> "*")) fp
should also return the contents of dir
.
Interestingly, this doesn't work in regular Unix tools, either. E.g., find . -name '/home/me/tmp/*'
doesn't return anything. So, perhaps the question is whether the Glob library is the right tool in all cases.
My intuition is that (globDir1 pat dir) is the same thing as (cd dir && echo pat), in which case what you want to do makes sense.