Skip to content

Commit

Permalink
target hint: suffix directory targets with /
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne Millon <[email protected]>
  • Loading branch information
emillon committed Nov 29, 2022
1 parent 6f66162 commit c638cc4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
43 changes: 22 additions & 21 deletions bin/target.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,37 @@ let target_hint (_setup : Dune_rules.Main.build_system) path =
assert (Path.is_managed path);
let open Memo.O in
let sub_dir = Option.value ~default:path (Path.parent path) in
(* CR-someday amokhov:
We currently provide the same hint for all targets. It would be nice to
indicate whether a hint corresponds to a file or to a directory target. *)
let root =
match sub_dir with
| External _ -> (* checked above *) assert false
| In_source_tree d -> d
| In_build_dir d -> Path.Build.drop_build_context_exn d
in
let+ candidates =
Load_rules.all_direct_targets (Some root) >>| Path.Build.Map.keys
in
let candidates =
if Path.is_in_build_dir path then List.map ~f:Path.build candidates
else
List.map candidates ~f:(fun path ->
match Path.Build.extract_build_context path with
| None -> Path.build path
| Some (_, path) -> Path.source path)
in
let+ candidates = Load_rules.all_direct_targets (Some root) in
let in_build = Path.is_in_build_dir path in
let candidates =
(* Only suggest hints for the basename, otherwise it's slow when there are
lots of files *)
List.filter_map candidates ~f:(fun path ->
Path.Build.Map.foldi candidates ~init:String.Set.empty
~f:(fun path (kind : Load_rules.target_type) acc ->
let path =
if in_build then Path.build path
else
match Path.Build.extract_build_context path with
| None -> Path.build path
| Some (_, path) -> Path.source path
in
(* Only suggest hints for the basename, otherwise it's slow when there are
lots of files *)
if Path.equal (Path.parent_exn path) sub_dir then
Some (Path.to_string path)
else None)
let path_s = Path.to_string path in
let s =
match kind with
| File -> path_s
| Directory -> path_s ^ "/"
in
String.Set.add acc s
else acc)
|> String.Set.to_list
in
let candidates = String.Set.of_list candidates |> String.Set.to_list in
User_message.did_you_mean (Path.to_string path) ~candidates

let resolve_path path ~(setup : Dune_rules.Main.build_system) =
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/directory-targets/main.t
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Hints for directory targets.

$ dune build outputs
Error: Don't know how to build outputs
Hint: did you mean output?
Hint: did you mean output/?
[1]

Print rules:
Expand Down

0 comments on commit c638cc4

Please sign in to comment.