From 8eba040b92886e0dee81fffbb673d6953d485177 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 8 May 2018 20:01:00 +0700 Subject: [PATCH] Rename Alias.of_path to Alias.of_user_written_path And add a loc argument for correct error messages --- src/build_system.ml | 5 +++-- src/build_system.mli | 2 +- src/super_context.ml | 4 +++- test/blackbox-tests/test-cases/bad-alias-error/run.t | 8 +++++--- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/build_system.ml b/src/build_system.ml index 890ddf67..eec4990e 100644 --- a/src/build_system.ml +++ b/src/build_system.ml @@ -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) diff --git a/src/build_system.mli b/src/build_system.mli index d55c6a8f..4abbcd2b 100644 --- a/src/build_system.mli +++ b/src/build_system.mli @@ -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: diff --git a/src/super_context.ml b/src/super_context.ml index 3787dc3f..29e8aaeb 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -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 -> diff --git a/test/blackbox-tests/test-cases/bad-alias-error/run.t b/test/blackbox-tests/test-cases/bad-alias-error/run.t index 864f6496..67f63b48 100644 --- a/test/blackbox-tests/test-cases/bad-alias-error/run.t +++ b/test/blackbox-tests/test-cases/bad-alias-error/run.t @@ -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