Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target hints: only load targets from subdir #6603

Merged
merged 3 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/print_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ let term =
let* request =
match targets with
| [] ->
Load_rules.all_direct_targets ()
Load_rules.all_direct_targets None
>>| Path.Build.Map.foldi ~init:[] ~f:(fun p _ acc ->
Path.build p :: acc)
>>| Action_builder.paths
Expand Down
21 changes: 13 additions & 8 deletions bin/target.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,23 @@ let request targets =
| Alias a -> Alias.request a)

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: There are two issues with the code below.
(* CR-someday amokhov:

(1) We first get *all* targets but then filter out only those that are
defined in the [sub_dir]. It would be better to just get the targets for
the [sub_dir] directly (the API supports this).

(2) We currently provide the same hint for all targets. It would be nice to
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+ candidates = Load_rules.all_direct_targets () >>| Path.Build.Map.keys in
let root =
match sub_dir with
| External e ->
Code_error.raise "target_hint: external path"
[ ("path", Path.External.to_dyn e) ]
| 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
Expand Down
7 changes: 5 additions & 2 deletions src/dune_engine/load_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,11 @@ end
module Source_tree_map_reduce =
Source_tree.Dir.Make_map_reduce (Memo) (All_targets)

let all_direct_targets () =
let* root = Source_tree.root ()
let all_direct_targets dir =
let* root =
match dir with
| None -> Source_tree.root ()
| Some dir -> Source_tree.nearest_dir dir
and* contexts = Memo.Lazy.force (Build_config.get ()).contexts in
Memo.parallel_map (Context_name.Map.values contexts) ~f:(fun ctx ->
Source_tree_map_reduce.map_reduce root ~traverse:Sub_dirs.Status.Set.all
Expand Down
8 changes: 6 additions & 2 deletions src/dune_engine/load_rules.mli
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ val is_target : Path.t -> is_target Memo.t
val is_under_directory_target : Path.t -> bool Memo.t

(** List of all buildable direct targets. This does not include files and
directory produced under a directory target. *)
val all_direct_targets : unit -> target_type Path.Build.Map.t Memo.t
directories produced under a directory target.

If argument is [None], load the root, otherwise only load targets from the
nearest subdirectory. *)
val all_direct_targets :
Path.Source.t option -> target_type Path.Build.Map.t Memo.t

type rule_or_source =
| Source of Digest.t
Expand Down