Make sure that Alias0.dir always goes through dir check
the directory must always be inside the build dir, so we make sure that any way to create the record validates this invariant
This commit is contained in:
parent
0f648f1387
commit
84831308f0
|
@ -212,7 +212,27 @@ module File_spec = struct
|
|||
end
|
||||
|
||||
module Alias0 = struct
|
||||
type t = { dir : Path.t; name : string }
|
||||
module T : sig
|
||||
type t = private
|
||||
{ dir : Path.t
|
||||
; name : string
|
||||
}
|
||||
val make : string -> dir:Path.t -> t
|
||||
end = struct
|
||||
type t =
|
||||
{ dir : Path.t
|
||||
; name : string
|
||||
}
|
||||
|
||||
let make name ~dir =
|
||||
if not (Path.is_in_build_dir dir) || String.contains name '/' then
|
||||
Exn.code_error "Alias0.make: Invalid alias"
|
||||
[ "name", Sexp.To_sexp.string name
|
||||
; "dir", Path.sexp_of_t dir
|
||||
];
|
||||
{ dir; name }
|
||||
end
|
||||
include T
|
||||
|
||||
let pp fmt t = Path.pp fmt (Path.relative t.dir t.name)
|
||||
|
||||
|
@ -222,24 +242,13 @@ module Alias0 = struct
|
|||
if not (Path.is_in_build_dir path) then
|
||||
die "Invalid alias!\nTried to reference alias %S"
|
||||
(Path.to_string_maybe_quoted path);
|
||||
{ dir = Path.parent path
|
||||
; name = Path.basename path
|
||||
}
|
||||
make ~dir:(Path.parent path) (Path.basename path)
|
||||
|
||||
let name t = t.name
|
||||
let dir t = t.dir
|
||||
|
||||
let fully_qualified_name t = Path.relative t.dir t.name
|
||||
|
||||
let make name ~dir =
|
||||
assert (not (String.contains name '/'));
|
||||
if not (Path.is_in_build_dir dir) then
|
||||
Exn.code_error "Alias0.make: Invalid alias"
|
||||
[ "name", Sexp.To_sexp.string name
|
||||
; "dir", Path.sexp_of_t dir
|
||||
];
|
||||
{ dir; name }
|
||||
|
||||
let stamp_file t =
|
||||
Path.relative (Path.insert_after_build_dir_exn t.dir ".aliases") (t.name ^ suffix)
|
||||
|
||||
|
|
Loading…
Reference in New Issue