diff --git a/master_changes.md b/master_changes.md index c06e31ae02d..950a52af988 100644 --- a/master_changes.md +++ b/master_changes.md @@ -32,6 +32,9 @@ users) * Fix package name display for no agreement conflicts [#6055 @rjbou - fix #6030] * Make fetching an archive from cache add missing symlinks [#6068 @kit-ty-kate - fix #6064] +## Build (package) + * ◈ Add `--verbose-on` option to enable verbose mode on specified package names [#5682 @desumn @rjbou] + ## Remove ## Switch @@ -136,6 +139,7 @@ users) * Add admin cache test [#6068 @rjbou] * env: Add a test for `build-env` overwrites build env opam environment variables [#5377 @rjbou] * clean: Add to check cleaning of sources directories [#5474 @rjbou] + * Add reftest for `--verbose-on` option [#5682 @rjbou] ### Engine @@ -158,6 +162,9 @@ users) # API updates ## opam-client * `OpamSwitchCommand.import`: add optional `?deps_only` argument to install only dependencies of root packages [#5388 @rjbou] + * `OpamArg.build_options`: add `--verbose-on` flag [#5682 @desumn @rjbou] + * `OpamClientConfig.build_options`: add `verbose_on` field [#5682 @desumn] + * `OpamClientConfig.E`, `OpamArg.environment_variables`: and `OPAMVERBOSEON` support [#5682 @desumn @rjbou] ## opam-repository * `OpamRepository.fetch_from_cache`: when an archive is found, add a symlink (or copy) for the ones found in opam file but not in cache [#6068 @kit-ty-kate] @@ -171,3 +178,4 @@ users) * Add `OpamTypesBase.switch_selections_{compare,equal}`: proper comparison functions for `OpamTypes.switch_selections` [#6102 @kit-ty-kate] ## opam-core + * `OpamStd.Env`: add `env_string_list` for parsing string list environment variables (comma separated) [#5682 @desumn] diff --git a/src/client/opamAction.ml b/src/client/opamAction.ml index da544b35502..9fc844efd29 100644 --- a/src/client/opamAction.ml +++ b/src/client/opamAction.ml @@ -688,7 +688,9 @@ let make_command st opam ?dir ?text_command (cmd, args) = OpamSystem.make_command ~env ~name ?dir ~text ~resolve_path:OpamStateConfig.(not !r.dryrun) ~metadata:["context", context] - ~verbose:(OpamConsole.verbose ()) + ~verbose:(OpamConsole.verbose () || + OpamPackage.Name.Set.mem (OpamPackage.name nv) + OpamClientConfig.(!r.verbose_on)) cmd args let remove_commands t nv = @@ -977,7 +979,10 @@ let build_package t ?(test=false) ?(doc=false) ?(dev_setup=false) build_dir nv = (OpamPackage.to_string nv) (OpamProcess.string_of_command cmd); Done (Some (OpamSystem.Process_error result)) | None, None -> - if commands <> [] && OpamConsole.verbose () then + if commands <> [] && (OpamConsole.verbose () || + OpamPackage.Name.Set.mem (OpamPackage.name nv) + OpamClientConfig.(!r.verbose_on)) + then OpamConsole.msg "%s compiled %s.%s\n" (if not (OpamConsole.utf8 ()) then "->" else OpamActionGraph. diff --git a/src/client/opamArg.ml b/src/client/opamArg.ml index 29d75df455d..b6c46eaddb2 100644 --- a/src/client/opamArg.ml +++ b/src/client/opamArg.ml @@ -304,6 +304,8 @@ let environment_variables = "see option `--skip-updates'."; "STATS", cli_original, (fun v -> STATS (env_bool v)), "display stats at the end of command."; + "VERBOSEON", cli_from cli2_2, (fun v -> VERBOSEON (env_string_list v)), + "see option --verbose-on"; "WORKINGDIR", cli_original, (fun v -> WORKINGDIR (env_bool v)), "see option `--working-dir'."; ] in @@ -647,19 +649,20 @@ type build_options = { lock_suffix : string; assume_depexts: bool; no_depexts : bool; + verbose_on : name list option; } let create_build_options keep_build_dir reuse_build_dir inplace_build make no_checksums req_checksums build_test build_doc dev_setup show dryrun skip_update fake jobs ignore_constraints_on unlock_base locked lock_suffix - assume_depexts no_depexts + assume_depexts no_depexts verbose_on = { keep_build_dir; reuse_build_dir; inplace_build; make; no_checksums; req_checksums; build_test; build_doc; dev_setup; show; dryrun; skip_update; fake; jobs; ignore_constraints_on; unlock_base; locked; lock_suffix; - assume_depexts; no_depexts; + assume_depexts; no_depexts; verbose_on; } let apply_build_options cli b = @@ -697,6 +700,10 @@ let apply_build_options cli b = ?fake:(flag b.fake) ?skip_dev_update:(flag b.skip_update) ?assume_depexts:(flag (b.assume_depexts || b.no_depexts)) + ?verbose_on: + (b.verbose_on >>= function + | [] -> None + | vo -> Some (OpamPackage.Name.Set.of_list vo)) ~scrubbed_environment_variables () @@ -1525,12 +1532,18 @@ let build_options cli = you installed the required dependency by hand. Implies \ $(b,--assume-depexts), and stores the exceptions upon success as well." in + let verbose_on = + mk_opt ~cli (cli_from cli2_3) ~section ["verbose-on"] "PACKAGES" + "Be more verbose on specific packages.\ + This is equivalent to setting $(b,\\$OPAMVERBOSE)." + Arg.(some (list package_name)) None + in Term.(const create_build_options $keep_build_dir $reuse_build_dir $inplace_build $make $no_checksums $req_checksums $build_test $build_doc $dev_setup $show $dryrun $skip_update $fake $jobs_flag ~section cli cli_original $ignore_constraints_on $unlock_base $locked $lock_suffix - $assume_depexts $no_depexts) + $assume_depexts $no_depexts $verbose_on) (* Option common to install commands *) let assume_built ?section cli = diff --git a/src/client/opamClientConfig.ml b/src/client/opamClientConfig.ml index c7acdbd72ef..8d9490d5ab8 100644 --- a/src/client/opamClientConfig.ml +++ b/src/client/opamClientConfig.ml @@ -31,6 +31,7 @@ module E = struct | SKIPUPDATE of bool option | STATS of bool option | WORKINGDIR of bool option + | VERBOSEON of string list option open OpamStd.Config.E let assumedepexts = value (function ASSUMEDEPEXTS b -> b | _ -> None) @@ -53,6 +54,7 @@ module E = struct let skipupdate = value (function SKIPUPDATE b -> b | _ -> None) let stats = value (function STATS b -> b | _ -> None) let workingdir = value (function WORKINGDIR b -> b | _ -> None) + let verboseon = value (function VERBOSEON s -> s | _ -> None) end @@ -76,6 +78,7 @@ type t = { assume_depexts: bool; cli: OpamCLIVersion.t; scrubbed_environment_variables: string list; + verbose_on : OpamTypes.name_set; } let default = { @@ -98,6 +101,7 @@ let default = { assume_depexts = false; cli = OpamCLIVersion.current; scrubbed_environment_variables = []; + verbose_on = OpamPackage.Name.Set.empty; } type 'a options_fun = @@ -120,6 +124,7 @@ type 'a options_fun = ?assume_depexts:bool -> ?cli:OpamCLIVersion.t -> ?scrubbed_environment_variables:string list -> + ?verbose_on:OpamTypes.name_set -> 'a let setk k t @@ -142,6 +147,7 @@ let setk k t ?assume_depexts ?cli ?scrubbed_environment_variables + ?verbose_on = let (+) x opt = match opt with Some x -> x | None -> x in k { @@ -163,7 +169,8 @@ let setk k t no_auto_upgrade = t.no_auto_upgrade + no_auto_upgrade; assume_depexts = t.assume_depexts + assume_depexts; cli = t.cli + cli; - scrubbed_environment_variables = t.scrubbed_environment_variables + scrubbed_environment_variables + scrubbed_environment_variables = t.scrubbed_environment_variables + scrubbed_environment_variables; + verbose_on = t.verbose_on + verbose_on; } let set t = setk (fun x () -> x) t @@ -198,6 +205,10 @@ let initk k = ?assume_depexts:(E.assumedepexts ()) ?cli:None ?scrubbed_environment_variables:None + ?verbose_on: + (E.verboseon () >>= function + | [] -> None + | vo -> Some (OpamPackage.Name.(Set.of_list (List.map of_string vo)))) let init ?noop:_ = initk (fun () -> ()) diff --git a/src/client/opamClientConfig.mli b/src/client/opamClientConfig.mli index a11077c8e13..6adeeafb1d0 100644 --- a/src/client/opamClientConfig.mli +++ b/src/client/opamClientConfig.mli @@ -33,6 +33,7 @@ module E: sig | SKIPUPDATE of bool option | STATS of bool option | WORKINGDIR of bool option + | VERBOSEON of string list option val cli: unit -> string option val rootisok: unit -> bool option val noaggregate: unit -> bool option @@ -59,6 +60,7 @@ type t = private { assume_depexts: bool; cli: OpamCLIVersion.t; scrubbed_environment_variables: string list; + verbose_on:OpamTypes.name_set; } type 'a options_fun = @@ -82,6 +84,7 @@ type 'a options_fun = ?assume_depexts:bool -> ?cli:OpamCLIVersion.t -> ?scrubbed_environment_variables:string list -> + ?verbose_on:OpamTypes.name_set -> 'a (* constraint 'a = 'b -> 'c *) @@ -120,6 +123,7 @@ val opam_init: ?assume_depexts:bool -> ?cli:OpamCLIVersion.t -> ?scrubbed_environment_variables:string list -> + ?verbose_on:OpamTypes.name_set -> ?original_root_dir:OpamTypes.dirname -> ?current_switch:OpamSwitch.t -> ?switch_from:OpamStateTypes.provenance -> diff --git a/src/core/opamStd.ml b/src/core/opamStd.ml index ddcf8c3de41..e18e58849ca 100644 --- a/src/core/opamStd.ml +++ b/src/core/opamStd.ml @@ -1854,6 +1854,9 @@ module Config = struct let env_string var = env (fun s -> s) var + let env_string_list var = + env (fun s -> OpamString.split s ',') var + let env_float var = env float_of_string var diff --git a/src/core/opamStd.mli b/src/core/opamStd.mli index 3ba4aa261f0..4e89f7115a3 100644 --- a/src/core/opamStd.mli +++ b/src/core/opamStd.mli @@ -698,6 +698,8 @@ module Config : sig val env_string: env_var -> string option + val env_string_list : env_var -> string list option + val env_float: env_var -> float option val env_when: env_var -> when_ option diff --git a/tests/reftests/dune.inc b/tests/reftests/dune.inc index 6cad84a211a..cbb93c3364b 100644 --- a/tests/reftests/dune.inc +++ b/tests/reftests/dune.inc @@ -1577,6 +1577,24 @@ %{targets} (run ./run.exe %{exe:../../src/client/opamMain.exe.exe} %{dep:var-option.test} %{read-lines:testing-env})))) +(rule + (alias reftest-verbose-on) + (action + (diff verbose-on.test verbose-on.out))) + +(alias + (name reftest) + (deps (alias reftest-verbose-on))) + +(rule + (targets verbose-on.out) + (deps root-N0REP0) + (package opam) + (action + (with-stdout-to + %{targets} + (run ./run.exe %{exe:../../src/client/opamMain.exe.exe} %{dep:verbose-on.test} %{read-lines:testing-env})))) + (rule (alias reftest-with-dev-setup) (action diff --git a/tests/reftests/verbose-on.test b/tests/reftests/verbose-on.test new file mode 100644 index 00000000000..2c0b64af801 --- /dev/null +++ b/tests/reftests/verbose-on.test @@ -0,0 +1,312 @@ +N0REP0 +### +opam-version: "2.0" +build: [ "echo" name ] +depends: "bar" +### +opam-version: "2.0" +build: [ "echo" name ] +depends: "baz" +### +opam-version: "2.0" +build: [ "echo" name ] +depends: "qux" +### +opam-version: "2.0" +build: [ "echo" name ] +### OPAMYES=1 +### opam switch create verbose-on --empty +### : with --verbose-on option +### opam install foo +The following actions will be performed: +=== install 4 packages + - install bar 1 [required by foo] + - install baz 1 [required by bar] + - install foo 1 + - install qux 1 [required by baz] + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> +-> installed qux.1 +-> installed baz.1 +-> installed bar.1 +-> installed foo.1 +Done. +### opam reinstall qux --verbose-on foo | unordered | sed-cmd echo +The following actions will be performed: +=== recompile 4 packages + - recompile bar 1 [uses baz] + - recompile baz 1 [uses qux] + - recompile foo 1 [uses bar] + - recompile qux 1 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> +-> removed foo.1 +-> removed bar.1 +-> removed baz.1 +-> removed qux.1 +-> installed qux.1 +-> installed baz.1 +-> installed bar.1 ++ echo "foo" (CWD=${BASEDIR}/OPAM/verbose-on/.opam-switch/build/foo.1) +- foo +-> compiled foo.1 +-> installed foo.1 +Done. +### opam reinstall qux --verbose-on bar | unordered | sed-cmd echo +The following actions will be performed: +=== recompile 4 packages + - recompile bar 1 [uses baz] + - recompile baz 1 [uses qux] + - recompile foo 1 [uses bar] + - recompile qux 1 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> +-> removed foo.1 +-> removed bar.1 +-> removed baz.1 +-> removed qux.1 +-> installed qux.1 +-> installed baz.1 ++ echo "bar" (CWD=${BASEDIR}/OPAM/verbose-on/.opam-switch/build/bar.1) +- bar +-> compiled bar.1 +-> installed bar.1 +-> installed foo.1 +Done. +### opam reinstall qux --verbose-on bar,qux | unordered | sed-cmd echo +The following actions will be performed: +=== recompile 4 packages + - recompile bar 1 [uses baz] + - recompile baz 1 [uses qux] + - recompile foo 1 [uses bar] + - recompile qux 1 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> ++ echo "qux" (CWD=${BASEDIR}/OPAM/verbose-on/.opam-switch/build/qux.1) +- qux +-> compiled qux.1 +-> removed foo.1 +-> removed bar.1 +-> removed baz.1 +-> removed qux.1 +-> installed qux.1 +-> installed baz.1 ++ echo "bar" (CWD=${BASEDIR}/OPAM/verbose-on/.opam-switch/build/bar.1) +- bar +-> compiled bar.1 +-> installed bar.1 +-> installed foo.1 +Done. +### opam reinstall qux --verbose-on foo,bar,baz,qux | unordered | sed-cmd echo +The following actions will be performed: +=== recompile 4 packages + - recompile bar 1 [uses baz] + - recompile baz 1 [uses qux] + - recompile foo 1 [uses bar] + - recompile qux 1 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> ++ echo "qux" (CWD=${BASEDIR}/OPAM/verbose-on/.opam-switch/build/qux.1) +- qux +-> compiled qux.1 +-> removed foo.1 +-> removed bar.1 +-> removed baz.1 +-> removed qux.1 +-> installed qux.1 ++ echo "baz" (CWD=${BASEDIR}/OPAM/verbose-on/.opam-switch/build/baz.1) +- baz +-> compiled baz.1 +-> installed baz.1 ++ echo "bar" (CWD=${BASEDIR}/OPAM/verbose-on/.opam-switch/build/bar.1) +- bar +-> compiled bar.1 +-> installed bar.1 ++ echo "foo" (CWD=${BASEDIR}/OPAM/verbose-on/.opam-switch/build/foo.1) +- foo +-> compiled foo.1 +-> installed foo.1 +Done. +### : unknown package +### opam reinstall qux --verbose-on unknown-pkg | unordered +The following actions will be performed: +=== recompile 4 packages + - recompile bar 1 [uses baz] + - recompile baz 1 [uses qux] + - recompile foo 1 [uses bar] + - recompile qux 1 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> +-> removed foo.1 +-> removed bar.1 +-> removed baz.1 +-> removed qux.1 +-> installed qux.1 +-> installed baz.1 +-> installed bar.1 +-> installed foo.1 +Done. +### : upgrade +### +opam-version: "2.0" +build: [ "echo" name ] +depends: "baz" +### opam upgrade --verbose-on bar | unordered | sed-cmd echo +The following actions will be performed: +=== recompile 1 package + - recompile foo 1 [uses bar] +=== upgrade 1 package + - upgrade bar 1 to 2 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> +-> removed foo.1 +-> removed bar.1 +-> installed bar.2 ++ echo "bar" (CWD=${BASEDIR}/OPAM/verbose-on/.opam-switch/build/bar.2) +- bar +-> compiled bar.2 +-> installed foo.1 +Done. +### : with OPAMVERBOSEON environment variable +### OPAMVERBOSEON=foo +### opam reinstall qux | unordered | sed-cmd echo +The following actions will be performed: +=== recompile 4 packages + - recompile bar 2 [uses baz] + - recompile baz 1 [uses qux] + - recompile foo 1 [uses bar] + - recompile qux 1 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> +-> removed foo.1 +-> removed bar.2 +-> removed baz.1 +-> removed qux.1 +-> installed qux.1 +-> installed baz.1 +-> installed bar.2 ++ echo "foo" (CWD=${BASEDIR}/OPAM/verbose-on/.opam-switch/build/foo.1) +- foo +-> compiled foo.1 +-> installed foo.1 +Done. +### OPAMVERBOSEON=bar +### opam reinstall qux | unordered | sed-cmd echo +The following actions will be performed: +=== recompile 4 packages + - recompile bar 2 [uses baz] + - recompile baz 1 [uses qux] + - recompile foo 1 [uses bar] + - recompile qux 1 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> +-> removed foo.1 +-> removed bar.2 +-> removed baz.1 +-> removed qux.1 +-> installed qux.1 +-> installed baz.1 ++ echo "bar" (CWD=${BASEDIR}/OPAM/verbose-on/.opam-switch/build/bar.2) +- bar +-> compiled bar.2 +-> installed bar.2 +-> installed foo.1 +Done. +### OPAMVERBOSEON=baz,qux +### opam reinstall qux | unordered | sed-cmd echo +The following actions will be performed: +=== recompile 4 packages + - recompile bar 2 [uses baz] + - recompile baz 1 [uses qux] + - recompile foo 1 [uses bar] + - recompile qux 1 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> ++ echo "qux" (CWD=${BASEDIR}/OPAM/verbose-on/.opam-switch/build/qux.1) +- qux +-> compiled qux.1 +-> removed foo.1 +-> removed bar.2 +-> removed baz.1 +-> removed qux.1 +-> installed qux.1 ++ echo "baz" (CWD=${BASEDIR}/OPAM/verbose-on/.opam-switch/build/baz.1) +- baz +-> compiled baz.1 +-> installed baz.1 +-> installed bar.2 +-> installed foo.1 +Done. +### OPAMVERBOSEON=foo,bar,baz,qux +### opam reinstall qux | unordered | sed-cmd echo +The following actions will be performed: +=== recompile 4 packages + - recompile bar 2 [uses baz] + - recompile baz 1 [uses qux] + - recompile foo 1 [uses bar] + - recompile qux 1 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> ++ echo "qux" (CWD=${BASEDIR}/OPAM/verbose-on/.opam-switch/build/qux.1) +- qux +-> compiled qux.1 +-> removed foo.1 +-> removed bar.2 +-> removed baz.1 +-> removed qux.1 +-> installed qux.1 ++ echo "baz" (CWD=${BASEDIR}/OPAM/verbose-on/.opam-switch/build/baz.1) +- baz +-> compiled baz.1 +-> installed baz.1 ++ echo "bar" (CWD=${BASEDIR}/OPAM/verbose-on/.opam-switch/build/bar.2) +- bar +-> compiled bar.2 +-> installed bar.2 ++ echo "foo" (CWD=${BASEDIR}/OPAM/verbose-on/.opam-switch/build/foo.1) +- foo +-> compiled foo.1 +-> installed foo.1 +Done. +### OPAMVERBOSEON="" +### opam reinstall qux | unordered +The following actions will be performed: +=== recompile 4 packages + - recompile bar 2 [uses baz] + - recompile baz 1 [uses qux] + - recompile foo 1 [uses bar] + - recompile qux 1 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> +-> removed foo.1 +-> removed bar.2 +-> removed baz.1 +-> removed qux.1 +-> installed qux.1 +-> installed baz.1 +-> installed bar.2 +-> installed foo.1 +Done. +### OPAMVERBOSEON=3 +### opam reinstall qux +Fatal error: Package name "3" should contain at least one letter +# Return code 99 # +### OPAMVERBOSEON=unknown-pkg +### opam reinstall qux | unordered +The following actions will be performed: +=== recompile 4 packages + - recompile bar 2 [uses baz] + - recompile baz 1 [uses qux] + - recompile foo 1 [uses bar] + - recompile qux 1 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> +-> removed foo.1 +-> removed bar.2 +-> removed baz.1 +-> removed qux.1 +-> installed qux.1 +-> installed baz.1 +-> installed bar.2 +-> installed foo.1 +Done.