Report better errors for globs pointing to non-existing directories (#413)

Fix #412
This commit is contained in:
Jérémie Dimino 2018-01-15 13:28:32 +00:00 committed by GitHub
parent eab1ff6c7b
commit af5d7f5e6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 8 deletions

View File

@ -42,6 +42,9 @@ next
- Add a `(promote (<file1> as <file2>) ...)` action allowing one to
promote generated files as source files (#402)
- Report better errors when using `(glob_files ...)` with a directory
that doesn't exist (#413, Fix #412)
1.0+beta16 (05/11/2017)
-----------------------

View File

@ -54,7 +54,7 @@ module Repr = struct
| Decided of bool * ('a, 'b) t
and glob_state =
| G_unevaluated of Path.t * Re.re
| G_unevaluated of Loc.t * Path.t * Re.re
| G_evaluated of Path.t list
let get_if_file_exists_exn state =
@ -132,7 +132,7 @@ let rec all = function
let path p = Paths (Pset.singleton p)
let paths ps = Paths (Pset.of_list ps)
let path_set ps = Paths ps
let paths_glob ~dir re = Paths_glob (ref (G_unevaluated (dir, re)))
let paths_glob ~loc ~dir re = Paths_glob (ref (G_unevaluated (loc, dir, re)))
let vpath vp = Vpath vp
let dyn_paths t = Dyn_paths t

View File

@ -37,7 +37,7 @@ val all : ('a, 'b) t list -> ('a, 'b list) t
val path : Path.t -> ('a, 'a) t
val paths : Path.t list -> ('a, 'a) t
val path_set : Path.Set.t -> ('a, 'a) t
val paths_glob : dir:Path.t -> Re.re -> ('a, Path.t list) t
val paths_glob : loc:Loc.t -> dir:Path.t -> Re.re -> ('a, Path.t list) t
val files_recursively_in : dir:Path.t -> file_tree:File_tree.t -> ('a, Path.Set.t) t
val vpath : 'a Vspec.t -> (unit, 'a) t
@ -173,7 +173,7 @@ module Repr : sig
| Decided of bool * ('a, 'b) t
and glob_state =
| G_unevaluated of Path.t * Re.re
| G_unevaluated of Loc.t * Path.t * Re.re
| G_evaluated of Path.t list
val get_if_file_exists_exn : ('a, 'b) if_file_exists_state ref -> ('a, 'b) t

View File

@ -42,9 +42,13 @@ let static_deps t ~all_targets_by_dir =
match !state with
| G_evaluated l ->
{ acc with action_deps = Pset.union acc.action_deps (Pset.of_list l) }
| G_unevaluated (dir, re) ->
| G_unevaluated (loc, dir, re) ->
match Pmap.find dir (Lazy.force all_targets_by_dir) with
| None -> acc
| None ->
Loc.warn loc "Directory %s doesn't exist."
(Path.to_string_maybe_quoted dir);
state := G_evaluated [];
acc
| Some targets ->
let result =
Pset.filter targets ~f:(fun path ->

View File

@ -437,12 +437,12 @@ module Deps = struct
>>^ fun () -> []
| Glob_files s -> begin
let path = Path.relative dir (expand_vars t ~scope ~dir s) in
let loc = String_with_vars.loc s in
match Glob_lexer.parse_string (Path.basename path) with
| Ok re ->
let dir = Path.parent path in
Build.paths_glob ~dir (Re.compile re)
Build.paths_glob ~loc ~dir (Re.compile re)
| Error (_pos, msg) ->
let loc = String_with_vars.loc s in
Loc.fail loc "invalid glob: %s" msg
end
| Files_recursively_in s ->

View File

@ -57,3 +57,9 @@
((name runtest)
(deps (pnd-result pnd-expected))
(action (run diff -u ${^}))))
;; Test for globs
(alias
((name runtest)
(deps ((glob_files dir-that-doesnt-exist/*)))))

View File

@ -1,4 +1,6 @@
$ $JBUILDER runtest -j1 --root .
File "jbuild", line 54, characters 10-209:
Warning: Directory _build/default/dir-that-doesnt-exist doesn't exist.
diff alias runtest
diff alias runtest
diff alias runtest