Skip to content

Do not keep log messages before initialization if the code is ran through a library #6487

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,5 @@ users)
## opam-format

## opam-core
* `OpamConsole.log`: does not keep log messages before initialization if the code is ran through a library [#6487 @kit-ty-kate]
* `OpamCoreConfig.in_opam`: was added [#6487 @kit-ty-kate]
1 change: 1 addition & 0 deletions src/client/opamCliMain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ let json_out () =
(Printexc.to_string e)

let main () =
OpamCoreConfig.set_in_opam ();
if Sys.win32 then begin
(* Disable the critical error handling dialog *)
ignore (OpamStubs.setErrorMode (1 lor OpamStubs.getErrorMode ()));
Expand Down
2 changes: 1 addition & 1 deletion src/core/opamConsole.ml
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ let log section ?(level=1) fmt =
| None -> debug_level
| exception Not_found -> 0
in
if not OpamCoreConfig.(!r.set) then
if not OpamCoreConfig.(!r.set) && OpamCoreConfig.(!r.in_opam) then
let b = Buffer.create 128 in
let timestamp = timestamp () ^ " " in
let k _ = Queue.push (level, timestamp, Buffer.contents b) pending in
Expand Down
5 changes: 5 additions & 0 deletions src/core/opamCoreConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type t = {
cygbin: string option;
git_location: string option;
set: bool;
in_opam: bool;
}

type 'a options_fun =
Expand Down Expand Up @@ -109,6 +110,7 @@ let default = {
cygbin = None;
git_location = None;
set = false;
in_opam = false;
}

let setk k t
Expand Down Expand Up @@ -151,6 +153,7 @@ let setk k t
cygbin = (match cygbin with Some _ -> cygbin | None -> t.cygbin);
git_location = (match git_location with Some _ -> git_location | None -> t.git_location);
set = true;
in_opam = t.in_opam;
}

let set t = setk (fun x () -> x) t
Expand Down Expand Up @@ -212,3 +215,5 @@ let answer_is_yes () =
| _ -> false

let developer = not (String.equal OpamCoreConfigDeveloper.value "")

let set_in_opam () = r := {default with in_opam = true}
6 changes: 6 additions & 0 deletions src/core/opamCoreConfig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ type t = private {
(** Windows specific: the full path of the git binary to use on Windows. *)
set : bool;
(** Options have not yet been initialised (i.e. defaults are active) *)
in_opam : bool;
(** Indicates that the code is running inside of opam and not as a library *)
}

type 'a options_fun =
Expand Down Expand Up @@ -136,3 +138,7 @@ val answer: unit -> OpamStd.Config.answer

(** [true] if OPAM was compiled in developer mode *)
val developer : bool

(** Indicates that the code currently runs inside opam, not a library.
Internal use only. *)
val set_in_opam : unit -> unit
Loading