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

Remove the external-lib-deps command #4298

Merged
3 commits merged into from Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ Unreleased
- Automatically delete left-over Merlin files when rebuilding for the first time
a project previously built with Dune `<= 2.7`. (#4261, @voodoos, @aalekseyev)

- Remove the `external-lib-deps` command. This command was only
approximative and the cost of maintainance was getting too high. We
removed it to make room for new more important features

2.8.2 (21/01/2021)
------------------

Expand Down
8 changes: 2 additions & 6 deletions bin/build_cmd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ let runtest =
let term =
let+ common = Common.term
and+ dirs = Arg.(value & pos_all string [ "." ] name_) in
Common.set_common common
~targets:
(List.map dirs ~f:(fun s ->
let dir = Path.Local.of_string s in
Arg.Dep.alias_rec ~dir Dune_engine.Alias.Name.runtest));
Common.set_common common;
let targets (setup : Import.Main.build_system) =
List.map dirs ~f:(fun dir ->
let dir = Path.(relative root) (Common.prefix_target common dir) in
Expand Down Expand Up @@ -116,7 +112,7 @@ let build =
| [] -> [ Common.default_target common ]
| _ :: _ -> targets
in
Common.set_common common ~targets;
Common.set_common common;
let targets setup = Target.resolve_targets_exn common setup targets in
run_build_command ~common ~targets
in
Expand Down
2 changes: 1 addition & 1 deletion bin/clean.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let command =
includes deleting the log file. Not only creating the log file would be
useless but with some FS this also causes [dune clean] to fail (cf
https://github.com/ocaml/dune/issues/2964). *)
Common.set_common common ~targets:[] ~log_file:No_log_file;
Common.set_common common ~log_file:No_log_file;
Build_system.files_in_source_tree_to_delete ()
|> Path.Set.iter ~f:Path.unlink_no_err;
Path.rm_rf Path.build_dir
Expand Down
18 changes: 2 additions & 16 deletions bin/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,10 @@ let normalize_path path =
else
path

let set_dirs c =
let set_common ?log_file c =
if c.root.dir <> Filename.current_dir_name then Sys.chdir c.root.dir;
Path.set_root (normalize_path (Path.External.cwd ()));
Path.Build.set_build_dir (Path.Build.Kind.of_string c.build_dir)

let set_common_other ?log_file c ~targets =
Path.Build.set_build_dir (Path.Build.Kind.of_string c.build_dir);
Dune_config.init c.config;
Dune_util.Log.init () ?file:log_file;
Clflags.debug_dep_path := c.debug_dep_path;
Expand All @@ -134,22 +132,10 @@ let set_common_other ?log_file c ~targets =
Clflags.no_print_directory := c.no_print_directory;
Clflags.store_orig_src_dir := c.store_orig_src_dir;
Clflags.promote_install_files := c.promote_install_files;
Clflags.external_lib_deps_hint :=
List.concat
[ [ "dune"; "external-lib-deps"; "--missing" ]
; c.orig_args
; List.map ~f:Arg.Dep.to_string_maybe_quoted targets
];
Clflags.always_show_command_line := c.always_show_command_line;
Clflags.ignore_promoted_rules := c.ignore_promoted_rules;
Option.iter ~f:Dune_engine.Stats.enable c.stats_trace_file

let set_common ?log_file ?external_lib_deps_mode c ~targets =
Option.iter external_lib_deps_mode ~f:(fun x ->
Clflags.external_lib_deps_mode := x);
set_dirs c;
set_common_other ?log_file c ~targets

let footer =
`Blocks
[ `S "BUGS"
Expand Down
25 changes: 4 additions & 21 deletions bin/common.mli
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,10 @@ val prefix_target : t -> string -> string

val instrument_with : t -> Dune_engine.Lib_name.t list option

(** [set_common ?log common ~targets ~external_lib_deps_mode] is
[set_dirs common] followed by [set_common_other common ~targets]. In
general, [set_common] executes sequence of side-effecting actions to
initialize Dune's working environment based on the options determined in a
[Common.t] record.contents. *)
val set_common :
?log_file:Dune_util.Log.File.t
-> ?external_lib_deps_mode:bool
-> t
-> targets:Arg.Dep.t list
-> unit

(** [set_common_other common ~targets] sets all stateful values dictated by
[common], except those accounted for by [set_dirs]. [targets] are used to
obtain external library dependency hints, if needed. *)
val set_common_other :
?log_file:Dune_util.Log.File.t -> t -> targets:Arg.Dep.t list -> unit

(** [set_dirs common] sets the workspace root and build directories, and makes
the root the current working directory *)
val set_dirs : t -> unit
(** [set_common] executes sequence of side-effecting actions to initialize
Dune's working environment based on the options determined in a [Common.t]
record.contents. *)
val set_common : ?log_file:Dune_util.Log.File.t -> t -> unit

(** [examples \[("description", "dune cmd foo"); ...\]] is an [EXAMPLES] manpage
section of enumerated examples illustrating how to run the documented
Expand Down
2 changes: 1 addition & 1 deletion bin/compute.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let term =
& info [] ~docv:"INPUT"
~doc:"Use $(docv) as the input to the function.")
in
Common.set_common common ~targets:[] ~external_lib_deps_mode:true;
Common.set_common common;
let action =
Scheduler.go ~common (fun () ->
let open Fiber.O in
Expand Down
2 changes: 1 addition & 1 deletion bin/describe.ml
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ let term =
and+ context_name = Common.context_arg ~doc:"Build context to use."
and+ format = Format.arg
and+ lang = Lang.arg in
Common.set_common common ~targets:[] ~external_lib_deps_mode:false;
Common.set_common common;
let what = What.parse what ~lang in
Scheduler.go ~common (fun () ->
let open Fiber.O in
Expand Down
2 changes: 1 addition & 1 deletion bin/exec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ let term =
value & flag
& info [ "no-build" ] ~doc:"don't rebuild target before executing")
and+ args = Arg.(value & pos_right 0 string [] (Arg.info [] ~docv:"ARGS")) in
Common.set_common common ~targets:[ Arg.Dep.file prog ];
Common.set_common common;
let setup =
Scheduler.go ~common (fun () -> Memo.Build.run (Import.Main.setup common))
in
Expand Down
188 changes: 14 additions & 174 deletions bin/external_lib_deps.ml
Original file line number Diff line number Diff line change
@@ -1,188 +1,28 @@
open Stdune
open! Stdune
open Import

let pp_external_libs libs =
Pp.enumerate (Lib_name.Map.to_list libs) ~f:(fun (name, kind) ->
match (kind : Lib_deps_info.Kind.t) with
| Optional -> Pp.textf "%s (optional)" (Lib_name.to_string name)
| Required -> Pp.textf "%s" (Lib_name.to_string name))

let doc = "Print out external libraries needed to build the given targets."
let doc = "Removed command."

let man =
[ `S "DESCRIPTION"
; `P {|Print out the external libraries needed to build the given targets.|}
; `P
{|The output of $(b,dune external-lib-deps @install) should be included
in what is written in your $(i,<package>.opam) file.|}
"This subcommand used to print out anapproximate set of external \
libraries that were required for building a given set of targets, \
without running the build. While this feature was useful, over time the \
quality of approximation had degraded and the cost of maintenance had \
increased, so we decided to remove it.\n"
; `Blocks Common.help_secs
]

let info = Term.info "external-lib-deps" ~doc ~man

let all_lib_deps ~request =
let targets = Build_system.static_deps_of_request request in
let rules = Build_system.rules_for_transitive_closure targets in
let lib_deps =
List.map rules ~f:(fun (rule : Dune_engine.Rule.t) ->
let deps = Lib_deps_info.lib_deps rule.action.build in
(rule, deps))
in
let module Context_name = Dune_engine.Context_name in
let contexts = Build_system.contexts () in
List.fold_left lib_deps ~init:[]
~f:(fun acc ((rule : Dune_engine.Rule.t), deps) ->
if Lib_name.Map.is_empty deps then
acc
else
match Path.Build.extract_build_context rule.dir with
| None -> acc
| Some (context, p) ->
let context = Context_name.of_string context in
(context, (p, deps)) :: acc)
|> Context_name.Map.of_list_multi
|> Context_name.Map.filteri ~f:(fun ctx _ ->
Context_name.Map.mem contexts ctx)
|> Context_name.Map.map
~f:(Path.Source.Map.of_list_reduce ~f:Lib_deps_info.merge)

let opam_install_command ?switch_name packages =
let cmd =
match switch_name with
| Some name -> Printf.sprintf "opam install --switch=%s" name
| None -> "opam install"
in
cmd :: packages |> String.concat ~sep:" "

let run ~lib_deps ~by_dir ~setup ~only_missing ~sexp =
Dune_engine.Context_name.Map.foldi lib_deps ~init:false
~f:(fun context_name lib_deps_by_dir acc ->
let lib_deps =
Path.Source.Map.values lib_deps_by_dir
|> List.fold_left ~init:Lib_name.Map.empty ~f:Lib_deps_info.merge
in
let sctx =
Dune_engine.Context_name.Map.find_exn setup.Import.Main.scontexts
context_name
in
let switch_name =
match (Super_context.context sctx).Context.kind with
| Default -> None
| Opam { switch; _ } -> Some switch
in
let internals = Super_context.internal_lib_names sctx in
let is_external name _kind = not (Lib_name.Set.mem internals name) in
let externals = Lib_name.Map.filteri lib_deps ~f:is_external in
if only_missing then (
if by_dir || sexp then
User_error.raise
[ Pp.textf
"--only-missing cannot be used with --unstable-by-dir or --sexp"
];
let context =
List.find_exn setup.workspace.contexts ~f:(fun c ->
Dune_engine.Context_name.equal c.name context_name)
in
let missing =
Lib_name.Map.filteri externals ~f:(fun name _ ->
not (Findlib.available context.findlib name))
in
if Lib_name.Map.is_empty missing then
acc
else if
Lib_name.Map.for_alli missing ~f:(fun _ kind ->
kind = Lib_deps_info.Kind.Optional)
then (
User_message.prerr
(User_error.make
[ Pp.textf
"The following libraries are missing in the %s context:"
(Dune_engine.Context_name.to_string context_name)
; pp_external_libs missing
]);
false
) else
let required_package_names =
Lib_name.Map.to_list missing
|> List.filter_map ~f:(fun (name, kind) ->
match (kind : Lib_deps_info.Kind.t) with
| Optional -> None
| Required -> Some (Lib_name.package_name name))
|> Package.Name.Set.of_list |> Package.Name.Set.to_list
|> List.map ~f:Package.Name.to_string
in
User_message.prerr
(User_error.make
[ Pp.textf
"The following libraries are missing in the %s context:"
(Dune_engine.Context_name.to_string context_name)
; pp_external_libs missing
]
~hints:
[ Dune_engine.Utils.pp_command_hint
(opam_install_command ?switch_name required_package_names)
]);
true
) else if sexp then (
if not by_dir then
User_error.raise [ Pp.textf "--sexp requires --unstable-by-dir" ];
let lib_deps_by_dir =
lib_deps_by_dir
|> Path.Source.Map.map ~f:(Lib_name.Map.filteri ~f:is_external)
|> Path.Source.Map.filter ~f:(fun m -> not (Lib_name.Map.is_empty m))
in
let sexp =
Path.Source.Map.to_dyn Lib_deps_info.to_dyn lib_deps_by_dir
|> Sexp.of_dyn
in
Format.printf "%a@." Pp.to_fmt
(Sexp.pp
(List
[ Atom (Dune_engine.Context_name.to_string context_name); sexp ]));
acc
) else (
if by_dir then
User_error.raise
[ Pp.textf "--unstable-by-dir cannot be used without --sexp" ];
User_message.print
(User_message.make
[ Pp.textf
"These are the external library dependencies in the %s \
context:"
(Dune_engine.Context_name.to_string context_name)
; pp_external_libs externals
]);
acc
))

let term =
let+ common = Common.term
and+ only_missing =
Arg.(
value & flag
& info [ "missing" ] ~doc:{|Only print out missing dependencies|})
and+ targets = Arg.(non_empty & pos_all dep [] & Arg.info [] ~docv:"TARGET")
and+ by_dir =
Arg.(
value & flag
& info [ "unstable-by-dir" ]
~doc:
{|Print dependencies per directory
(this feature is currently unstable)|})
and+ sexp =
Arg.(value & flag & info [ "sexp" ] ~doc:{|Produce a s-expression output|})
in
Common.set_common common ~targets:[] ~external_lib_deps_mode:true;
let setup, lib_deps =
Scheduler.go ~common (fun () ->
let open Fiber.O in
let+ setup = Memo.Build.run (Import.Main.setup common) in
let targets = Target.resolve_targets_exn common setup targets in
let request = Target.request targets in
let deps = all_lib_deps ~request in
(setup, deps))
in
let failure = run ~by_dir ~setup ~lib_deps ~sexp ~only_missing in
if failure then raise Dune_util.Report_error.Already_reported
Term.ret
@@ let+ _ = Common.term
and+ _ = Arg.(value & flag & info [ "missing" ] ~doc:{|unused|})
snowleopard marked this conversation as resolved.
Show resolved Hide resolved
and+ _ = Arg.(value & pos_all dep [] & Arg.info [] ~docv:"TARGET")
and+ _ = Arg.(value & flag & info [ "unstable-by-dir" ] ~doc:{|unused|})
and+ _ = Arg.(value & flag & info [ "sexp" ] ~doc:{|unused|}) in
`Error (false, "This subcommand is no longer implemented.")

let command = (term, info)
1 change: 0 additions & 1 deletion bin/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module Super_context = Dune_rules.Super_context
module Context = Dune_rules.Context
module Config = Dune_engine.Config
module Lib_name = Dune_engine.Lib_name
module Lib_deps_info = Dune_rules.Lib_deps_info
module Build_system = Dune_engine.Build_system
module Findlib = Dune_rules.Findlib
module Package = Dune_engine.Package
Expand Down
2 changes: 1 addition & 1 deletion bin/init.ml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ let term =
& opt (some (enum Component.Options.Project.Pkg.commands)) None
& info [ "pkg" ] ~docv ~doc)
in
Common.set_common common_term ~targets:[];
Common.set_common common_term;
let open Component in
let context = Init_context.make path in
let common : Options.Common.t = { name; libraries; pps } in
Expand Down
2 changes: 1 addition & 1 deletion bin/install_uninstall.ml
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ let install_uninstall ~what =
"Select context to install from. By default, install files from \
all defined contexts.")
and+ sections = Sections.term in
Common.set_common ~log_file:No_log_file common ~targets:[];
Common.set_common ~log_file:No_log_file common;
Scheduler.go ~common (fun () ->
let open Fiber.O in
let* workspace = Memo.Build.run (Import.Main.scan_workspace common) in
Expand Down
2 changes: 1 addition & 1 deletion bin/installed_libraries.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let term =
& info [ "na"; "not-available" ]
~doc:"List libraries that are not available and explain why")
in
Common.set_common common ~targets:[];
Common.set_common common;
let capture_outputs = Common.capture_outputs common in
let _env : Env.t = Import.Main.setup_env ~capture_outputs in
Scheduler.go ~common (fun () ->
Expand Down
4 changes: 2 additions & 2 deletions bin/ocaml_merlin.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let term =
debugging purposes only and should not be considered as a stable \
ouptut.")
in
Common.set_common common ~log_file:No_log_file ~targets:[];
Common.set_common common ~log_file:No_log_file;
Dune_engine.File_tree.init ~recognize_jbuilder_projects:true
~ancestor_vcs:None;
let x = Common.x common in
Expand Down Expand Up @@ -69,7 +69,7 @@ module Dump_dot_merlin = struct
"The path to the folder of which the configuration should be \
printed. Defaults to the current directory.")
in
Common.set_common common ~log_file:No_log_file ~targets:[];
Common.set_common common ~log_file:No_log_file;
Dune_engine.File_tree.init ~recognize_jbuilder_projects:true
~ancestor_vcs:None;
let x = Common.x common in
Expand Down
Loading