Skip to content

Commit

Permalink
Merge pull request ocaml#5682 from desumn/install-verbose-on
Browse files Browse the repository at this point in the history
Add a verbose-on option.
  • Loading branch information
rjbou authored Jul 26, 2024
2 parents 715b62d + 0d2588d commit efdc5d5
Show file tree
Hide file tree
Showing 9 changed files with 382 additions and 6 deletions.
8 changes: 8 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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]
Expand All @@ -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]
9 changes: 7 additions & 2 deletions src/client/opamAction.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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.
Expand Down
19 changes: 16 additions & 3 deletions src/client/opamArg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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
()

Expand Down Expand Up @@ -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 =
Expand Down
13 changes: 12 additions & 1 deletion src/client/opamClientConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -76,6 +78,7 @@ type t = {
assume_depexts: bool;
cli: OpamCLIVersion.t;
scrubbed_environment_variables: string list;
verbose_on : OpamTypes.name_set;
}

let default = {
Expand All @@ -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 =
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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 () -> ())

Expand Down
4 changes: 4 additions & 0 deletions src/client/opamClientConfig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 =
Expand All @@ -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 *)

Expand Down Expand Up @@ -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 ->
Expand Down
3 changes: 3 additions & 0 deletions src/core/opamStd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/core/opamStd.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/reftests/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit efdc5d5

Please sign in to comment.