Rename Alias.of_path to Alias.of_user_written_path

And add a loc argument for correct error messages
This commit is contained in:
Rudi Grinberg 2018-05-08 20:01:00 +07:00
parent 76c1a32da4
commit 8eba040b92
4 changed files with 12 additions and 7 deletions

View File

@ -238,9 +238,10 @@ module Alias0 = struct
let suffix = "-" ^ String.make 32 '0'
let of_path path =
let of_user_written_path ~loc path =
if not (Path.is_in_build_dir path) then
die "Invalid alias!\nTried to reference alias %S"
Loc.fail loc "Invalid alias!\n\
Tried to reference path outside build dir: %S"
(Path.to_string_maybe_quoted path);
make ~dir:(Path.parent path) (Path.basename path)

View File

@ -99,7 +99,7 @@ module Alias : sig
val make : string -> dir:Path.t -> t
val of_path : Path.t -> t
val of_user_written_path : loc:Loc.t -> Path.t -> t
(** The following always holds:

View File

@ -457,7 +457,9 @@ module Deps = struct
open Dep_conf
let make_alias t ~scope ~dir s =
Alias.of_path (Path.relative dir (expand_vars t ~scope ~dir s))
let loc = String_with_vars.loc s in
Alias.of_user_written_path ~loc
(Path.relative ~error_loc:loc dir (expand_vars t ~scope ~dir s))
let dep t ~scope ~dir = function
| File s ->

View File

@ -1,5 +1,7 @@
$ dune runtest --root absolute-path 2>&1 | grep -v Entering
Invalid alias!
Tried to reference alias "/foo/bar"
File "jbuild", line 3, characters 16-24:
Error: Invalid alias!
Tried to reference path outside build dir: "/foo/bar"
$ dune runtest --root outside-workspace 2>&1 | grep -v Entering
Path outside the workspace: ./../../../foobar from _build/default
File "jbuild", line 4, characters 16-39:
Error: path outside the workspace: ./../../../foobar from _build/default