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

refactor: artifact binary improvement #8733

Merged
merged 1 commit into from
Sep 22, 2023
Merged
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
45 changes: 21 additions & 24 deletions src/dune_rules/artifacts.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,34 @@ module Bin = struct
()
;;

let binary t ?hint ~loc name =
let analyze_binary t name =
match Filename.is_relative name with
| false -> Memo.return (Ok (Path.of_filename_relative_to_initial_cwd name))
| false -> Memo.return (Some (Path.of_filename_relative_to_initial_cwd name))
| true ->
let* local_bins = Memo.Lazy.force t.local_bins in
(match Filename.Map.find local_bins name with
| Some path -> Memo.return (Ok (Path.build path))
| None ->
Context.which t.context name
>>| (function
| Some p -> Ok p
| None ->
Error
(let context = Context.name t.context in
Action.Prog.Not_found.create ~program:name ?hint ~context ~loc ())))
| Some path -> Memo.return (Some (Path.build path))
| None -> Context.which t.context name)
;;

let binary t ?hint ~loc name =
analyze_binary t name
>>| function
| Some path -> Ok path
| None ->
let context = Context.name t.context in
Error (Action.Prog.Not_found.create ~program:name ?hint ~context ~loc ())
;;

let binary_available t name =
match Filename.is_relative name with
| false ->
Fs_memo.file_exists
(External (Path.External.of_filename_relative_to_initial_cwd name))
| true ->
let* local_bins = Memo.Lazy.force t.local_bins in
(match Filename.Map.find local_bins name with
| Some _ -> Memo.return true
| None ->
Context.which t.context name
>>| (function
| Some _ -> true
| None -> false))
analyze_binary t name
>>= function
| None -> Memo.return false
| Some path ->
(match path with
| External e -> Fs_memo.file_exists @@ External e
| In_source_tree e -> Fs_memo.file_exists @@ In_source_dir e
| In_build_dir _ -> Build_system.file_exists path)
;;

let add_binaries t ~dir l =
Expand Down