Skip to content

Commit 6c38d9a

Browse files
committed
Do not keep log messages before initialization if the code is ran through a library
1 parent f833600 commit 6c38d9a

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed

master_changes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,5 @@ users)
127127
## opam-format
128128

129129
## opam-core
130+
* `OpamConsole.log`: does not keep log messages before initialization if the code is ran through a library [#6487 @kit-ty-kate]
131+
* `OpamCoreConfig.in_opam`: was added [#6487 @kit-ty-kate]

src/client/opamCliMain.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ let json_out () =
483483
(Printexc.to_string e)
484484

485485
let main () =
486+
OpamCoreConfig.set_in_opam ();
486487
if Sys.win32 then begin
487488
(* Disable the critical error handling dialog *)
488489
ignore (OpamStubs.setErrorMode (1 lor OpamStubs.getErrorMode ()));

src/core/opamConsole.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ let log section ?(level=1) fmt =
562562
| None -> debug_level
563563
| exception Not_found -> 0
564564
in
565-
if not OpamCoreConfig.(!r.set) then
565+
if not OpamCoreConfig.(!r.set) && OpamCoreConfig.(!r.in_opam) then
566566
let b = Buffer.create 128 in
567567
let timestamp = timestamp () ^ " " in
568568
let k _ = Queue.push (level, timestamp, Buffer.contents b) pending in

src/core/opamCoreConfig.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type t = {
6767
cygbin: string option;
6868
git_location: string option;
6969
set: bool;
70+
in_opam: bool;
7071
}
7172

7273
type 'a options_fun =
@@ -109,6 +110,7 @@ let default = {
109110
cygbin = None;
110111
git_location = None;
111112
set = false;
113+
in_opam = false;
112114
}
113115

114116
let setk k t
@@ -151,6 +153,7 @@ let setk k t
151153
cygbin = (match cygbin with Some _ -> cygbin | None -> t.cygbin);
152154
git_location = (match git_location with Some _ -> git_location | None -> t.git_location);
153155
set = true;
156+
in_opam = t.in_opam;
154157
}
155158

156159
let set t = setk (fun x () -> x) t
@@ -212,3 +215,5 @@ let answer_is_yes () =
212215
| _ -> false
213216

214217
let developer = not (String.equal OpamCoreConfigDeveloper.value "")
218+
219+
let set_in_opam () = r := {default with in_opam = true}

src/core/opamCoreConfig.mli

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ type t = private {
7878
(** Windows specific: the full path of the git binary to use on Windows. *)
7979
set : bool;
8080
(** Options have not yet been initialised (i.e. defaults are active) *)
81+
in_opam : bool;
82+
(** Indicates that the code is running inside of opam and not as a library *)
8183
}
8284

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

137139
(** [true] if OPAM was compiled in developer mode *)
138140
val developer : bool
141+
142+
(** Indicates that the code currently runs inside opam, not a library.
143+
Internal use only. *)
144+
val set_in_opam : unit -> unit

0 commit comments

Comments
 (0)