diff --git a/CHANGES.md b/CHANGES.md index c782e533..a8b9bfaf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -42,6 +42,9 @@ next - Add a `(promote ( as ) ...)` 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) ----------------------- diff --git a/src/build.ml b/src/build.ml index 16d15f5b..2ff4f92e 100644 --- a/src/build.ml +++ b/src/build.ml @@ -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 diff --git a/src/build.mli b/src/build.mli index 026b9bc0..39ebd937 100644 --- a/src/build.mli +++ b/src/build.mli @@ -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 diff --git a/src/build_interpret.ml b/src/build_interpret.ml index de9b50ff..0a140de5 100644 --- a/src/build_interpret.ml +++ b/src/build_interpret.ml @@ -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 -> diff --git a/src/super_context.ml b/src/super_context.ml index 34594047..90c3a2f3 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -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 -> diff --git a/test/blackbox-tests/test-cases/misc/jbuild b/test/blackbox-tests/test-cases/misc/jbuild index 55446cd8..8629755f 100644 --- a/test/blackbox-tests/test-cases/misc/jbuild +++ b/test/blackbox-tests/test-cases/misc/jbuild @@ -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/*))))) diff --git a/test/blackbox-tests/test-cases/misc/run.t b/test/blackbox-tests/test-cases/misc/run.t index a2ac0a8e..9b2802e2 100644 --- a/test/blackbox-tests/test-cases/misc/run.t +++ b/test/blackbox-tests/test-cases/misc/run.t @@ -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