Skip to content

Commit

Permalink
Merge pull request ocaml#3723 from rjbou/dispvars
Browse files Browse the repository at this point in the history
Fix variable display
  • Loading branch information
rjbou authored Jan 22, 2019
2 parents a92c80b + 6ef38a1 commit 0b5dcaa
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 24 deletions.
64 changes: 41 additions & 23 deletions src/client/opamConfigCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,25 @@ let help t =
all_global_vars
(OpamVariable.Map.map snd t.switch_global.global_variables)
in
List.map (fun (var, doc) -> [
let env = OpamPackageVar.resolve t in
List.map (fun (var, doc) ->
let content =
OpamFilter.ident_string env ~default:"" ([],var,None)
in
let doc =
if doc = OpamGlobalState.inferred_from_system then
match OpamStd.Option.Op.(
OpamVariable.Map.find_opt var t.switch_global.global_variables
>>| fst
>>= Lazy.force) with
| Some c when (OpamVariable.string_of_variable_contents c) <> content ->
"Set throught local opam config or env"
| _ -> doc
else doc
in
[
OpamVariable.to_string var % `bold;
OpamFilter.ident_string (OpamPackageVar.resolve t) ~default:""
([],var,None) % `blue;
content % `blue;
"#"; doc
])
(OpamVariable.Map.bindings all_global_vars) |>
Expand Down Expand Up @@ -315,32 +330,35 @@ let set_global var value =
OpamGlobalState.write { gt with config }

let variable gt v =
match OpamPackageVar.resolve_global gt v with
| Some c ->
OpamConsole.msg "%s\n" (OpamVariable.string_of_variable_contents c)
| None ->
let raw_switch_content =
match OpamStateConfig.get_switch_opt () with
| None ->
OpamConsole.error_and_exit `Not_found
"Variable %s not found"
(OpamVariable.Full.to_string v)
| Some switch ->
let switch_config =
OpamFile.Switch_config.safe_read
(OpamPath.Switch.switch_config gt.root switch)
in
match OpamPackageVar.resolve_switch_raw gt switch switch_config v with
| Some c ->
OpamConsole.msg "%s\n" (OpamVariable.string_of_variable_contents c)
| None ->
OpamSwitchState.with_ `Lock_none gt @@ fun st ->
match OpamPackageVar.resolve st v with
| Some c ->
OpamConsole.msg "%s\n" (OpamVariable.string_of_variable_contents c)
| None ->
OpamConsole.error_and_exit `Not_found
"Variable %s not found"
(OpamVariable.Full.to_string v)
OpamPackageVar.resolve_switch_raw gt switch switch_config v
| None -> None
in
let switch_content =
match raw_switch_content with
| None when not (OpamVariable.Full.is_global v) ->
OpamSwitchState.with_ `Lock_none gt @@ fun st ->
OpamPackageVar.resolve st v
| rsc -> rsc
in
let content =
match switch_content with
| Some _ as some -> some
| None -> OpamPackageVar.resolve_global gt v
in
match content with
| Some c -> OpamConsole.msg "%s\n" (OpamVariable.string_of_variable_contents c)
| None ->
OpamConsole.error_and_exit `Not_found
"Variable %s not found"
(OpamVariable.Full.to_string v)


let exec gt ?set_opamroot ?set_opamswitch ~inplace_path command =
log "config-exec command=%a" (slog (String.concat " ")) command;
Expand Down
6 changes: 5 additions & 1 deletion src/state/opamGlobalState.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ let load_config global_lock root =
OpamFormatUpgrade.as_necessary global_lock root config;
config

let inferred_from_system = "Inferred from system"

let load lock_kind =
let root = OpamStateConfig.(!r.root_dir) in
log "LOAD-GLOBAL-STATE @ %a" (slog OpamFilename.Dir.to_string) root;
Expand Down Expand Up @@ -64,7 +66,9 @@ let load lock_kind =
List.fold_left (fun acc (v,value) ->
OpamVariable.Map.add v
(lazy (Some (OpamStd.Option.default (S "unknown") (Lazy.force value))),
"Inferred from system")
(* Careful on changing it, it is used to determine user defined
variables on `config report`. See [OpamConfigCommand.help]. *)
inferred_from_system)
acc)
OpamVariable.Map.empty
(OpamSysPoll.variables)
Expand Down
3 changes: 3 additions & 0 deletions src/state/opamGlobalState.mli
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ val write: rw global_state -> unit
registered if it is set and exists, and removing any non-existing switches.
Writes back to disk if possible (ie lock is available) *)
val fix_switch_list: 'a global_state -> 'a global_state

(** Description used for system inferred variables *)
val inferred_from_system: string

0 comments on commit 0b5dcaa

Please sign in to comment.