Split target resolution from string -> path conversion
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
parent
6197a49c41
commit
264263c819
42
bin/main.ml
42
bin/main.ml
|
@ -659,26 +659,8 @@ let check_path contexts =
|
||||||
name
|
name
|
||||||
(hint name (String.Set.to_list contexts))
|
(hint name (String.Set.to_list contexts))
|
||||||
|
|
||||||
let resolve_target common (setup : Main.setup) s =
|
let resolve_path path ~(setup : Main.setup) =
|
||||||
let check_path = check_path setup.contexts in
|
let check_path = check_path setup.contexts in
|
||||||
if String.is_prefix s ~prefix:"@" then begin
|
|
||||||
let pos, is_rec =
|
|
||||||
if String.length s >= 2 && s.[1] = '@' then
|
|
||||||
(2, false)
|
|
||||||
else
|
|
||||||
(1, true)
|
|
||||||
in
|
|
||||||
let s = String.sub s ~pos ~len:(String.length s - pos) in
|
|
||||||
let path = Path.relative Path.root (prefix_target common s) in
|
|
||||||
check_path path;
|
|
||||||
if Path.is_root path then
|
|
||||||
die "@@ on the command line must be followed by a valid alias name"
|
|
||||||
else if not (Path.is_managed path) then
|
|
||||||
die "@@ on the command line must be followed by a relative path"
|
|
||||||
else
|
|
||||||
Ok [if is_rec then Alias_rec path else Alias path]
|
|
||||||
end else begin
|
|
||||||
let path = Path.relative Path.root (prefix_target common s) in
|
|
||||||
check_path path;
|
check_path path;
|
||||||
let can't_build path =
|
let can't_build path =
|
||||||
Error (path, target_hint setup path);
|
Error (path, target_hint setup path);
|
||||||
|
@ -701,6 +683,28 @@ let resolve_target common (setup : Main.setup) s =
|
||||||
with
|
with
|
||||||
| [] -> can't_build path
|
| [] -> can't_build path
|
||||||
| l -> Ok l
|
| l -> Ok l
|
||||||
|
|
||||||
|
let resolve_target common (setup : Main.setup) s =
|
||||||
|
let check_path = check_path setup.contexts in
|
||||||
|
if String.is_prefix s ~prefix:"@" then begin
|
||||||
|
let pos, is_rec =
|
||||||
|
if String.length s >= 2 && s.[1] = '@' then
|
||||||
|
(2, false)
|
||||||
|
else
|
||||||
|
(1, true)
|
||||||
|
in
|
||||||
|
let s = String.sub s ~pos ~len:(String.length s - pos) in
|
||||||
|
let path = Path.relative Path.root (prefix_target common s) in
|
||||||
|
check_path path;
|
||||||
|
if Path.is_root path then
|
||||||
|
die "@@ on the command line must be followed by a valid alias name"
|
||||||
|
else if not (Path.is_managed path) then
|
||||||
|
die "@@ on the command line must be followed by a relative path"
|
||||||
|
else
|
||||||
|
Ok [if is_rec then Alias_rec path else Alias path]
|
||||||
|
end else begin
|
||||||
|
let path = Path.relative Path.root (prefix_target common s) in
|
||||||
|
resolve_path path ~setup
|
||||||
end
|
end
|
||||||
|
|
||||||
let log_targets ~log targets =
|
let log_targets ~log targets =
|
||||||
|
|
Loading…
Reference in New Issue