Skip to content

Commit

Permalink
refactor: move [Dune_load.Dune_files.in_dir] (ocaml#9768)
Browse files Browse the repository at this point in the history
It doesn't need to be in the [Dune_files] submodule

Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
  • Loading branch information
rgrinberg authored and emillon committed Feb 5, 2024
1 parent edb835e commit 228e284
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion bin/describe/describe_pp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ let get_pped_file super_context file =
>>| Source_tree.Dir.path
>>| Path.source
in
let* dune_file = Dune_rules.Dune_load.Dune_files.in_dir (dir |> in_build_dir) in
let* dune_file = Dune_rules.Dune_load.in_dir (dir |> in_build_dir) in
let staged_pps =
Option.bind dune_file ~f:(fun dune_file ->
dune_file.stanzas
Expand Down
56 changes: 28 additions & 28 deletions src/dune_rules/dune_load.ml
Original file line number Diff line number Diff line change
Expand Up @@ -253,34 +253,6 @@ module Dune_files = struct
Memo.exec memo (dir, project, dune_file)
;;

let in_dir dir =
let source_dir = Path.Build.drop_build_context_exn dir in
Source_tree.find_dir source_dir
>>= function
| None -> Memo.return None
| Some d ->
(match Source_tree.Dir.dune_file d with
| None -> Memo.return None
| Some dune_file ->
let project = Source_tree.Dir.project d in
interpret ~dir:source_dir ~project ~dune_file
>>= (function
| Literal dune_file -> Memo.return (Some dune_file)
| Script script ->
let context =
match Install.Context.of_path dir with
| Some c -> c
| None ->
User_error.raise
[ Pp.textf
"no context in directory %s"
(Path.Build.to_string_maybe_quoted dir)
]
in
let+ dune_file = Script.eval_one ~context script in
Some dune_file))
;;

let eval dune_files ~context =
let open Memo.O in
let static, dynamic =
Expand Down Expand Up @@ -367,6 +339,34 @@ let load () =
}
;;

let in_dir dir =
let source_dir = Path.Build.drop_build_context_exn dir in
Source_tree.find_dir source_dir
>>= function
| None -> Memo.return None
| Some d ->
(match Source_tree.Dir.dune_file d with
| None -> Memo.return None
| Some dune_file ->
let project = Source_tree.Dir.project d in
Dune_files.interpret ~dir:source_dir ~project ~dune_file
>>= (function
| Literal dune_file -> Memo.return (Some dune_file)
| Script script ->
let context =
match Install.Context.of_path dir with
| Some c -> c
| None ->
User_error.raise
[ Pp.textf
"no context in directory %s"
(Path.Build.to_string_maybe_quoted dir)
]
in
let+ dune_file = Script.eval_one ~context script in
Some dune_file))
;;

let load =
let memo = Memo.lazy_ ~name:"dune_load" load in
fun () -> Memo.Lazy.force memo
Expand Down
2 changes: 1 addition & 1 deletion src/dune_rules/dune_load.mli
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ module Dune_files : sig
type t

val eval : t -> context:Context_name.t -> Dune_file.t list Memo.t
val in_dir : Path.Build.t -> Dune_file.t option Memo.t
end

type t

val in_dir : Path.Build.t -> Dune_file.t option Memo.t
val dune_files : t -> Dune_files.t
val packages : t -> Package.t Package.Name.Map.t
val projects : t -> Dune_project.t list
Expand Down
2 changes: 1 addition & 1 deletion src/dune_rules/only_packages.ml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ let stanzas_in_dir dir =
if Path.Build.is_root dir
then Memo.return None
else
Dune_load.Dune_files.in_dir dir
Dune_load.in_dir dir
>>= function
| None -> Memo.return None
| Some dune_file ->
Expand Down

0 comments on commit 228e284

Please sign in to comment.