Skip to content

Commit 143ce01

Browse files
committed
CP-17268 move bisect setup code into a module of its own
We need this code for the other binaries in this repo, too. Hence, it better lives in its own module Signed-off-by: Christian Lindig <[email protected]>
1 parent 82a8930 commit 143ce01

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

lib/bisect_setup.ml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
(** set up the BISECT_FILE env var to point to a temp directory where
2+
* the log files go
3+
*)
4+
5+
module D = Debug.Make(struct let name = "bisect_setup" end)
6+
7+
let init name =
8+
let (//) = Filename.concat in
9+
let tmpdir =
10+
let getenv n = try Sys.getenv n with Not_found -> "" in
11+
let dirs =
12+
[ getenv "TMP"
13+
; getenv "TEMP"
14+
; "/tmp"
15+
; "/usr/tmp"
16+
; "/var/tmp"
17+
] in
18+
let is_dir = function
19+
| "" -> false
20+
| path -> try Sys.is_directory path with Sys_error _ -> false
21+
in try
22+
List.find is_dir dirs
23+
with
24+
Not_found -> D.error "can't find temp directory %s" __LOC__; exit 1
25+
in try
26+
ignore (Sys.getenv "BISECT_FILE")
27+
with Not_found ->
28+
Unix.putenv "BISECT_FILE" (tmpdir // Printf.sprintf "bisect-%s" name)
29+

lib/xenopsd.ml

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -120,32 +120,7 @@ let configure ?(specific_options=[]) ?(specific_essential_paths=[]) ?(specific_n
120120
error "%s" m;
121121
exit 1
122122

123-
(** set up the BISECT_FILE env var to point to a temp directory where
124-
* the log files go
125-
*)
126-
let setup_bisect name =
127-
let (//) = Filename.concat in
128-
let tmpdir =
129-
let getenv n = try Sys.getenv n with Not_found -> "" in
130-
let dirs =
131-
[ getenv "TMP"
132-
; getenv "TEMP"
133-
; "/tmp"
134-
; "/usr/tmp"
135-
; "/var/tmp"
136-
] in
137-
let is_dir = function
138-
| "" -> false
139-
| path -> try Sys.is_directory path with Sys_error _ -> false
140-
in try
141-
List.find is_dir dirs
142-
with
143-
Not_found -> error "can't find temp directory %s" __LOC__; exit 1
144-
in try
145-
ignore (Sys.getenv "BISECT_FILE")
146-
with Not_found ->
147-
Unix.putenv "BISECT_FILE" (tmpdir // Printf.sprintf "bisect-%s" name)
148-
123+
149124
let main backend =
150125
Printexc.record_backtrace true;
151126

@@ -174,7 +149,7 @@ let main backend =
174149
Sys.set_signal Sys.sigpipe Sys.Signal_ignore;
175150
Sys.set_signal Sys.sigterm (Sys.Signal_handle signal_handler);
176151

177-
setup_bisect name; (* set up coverage profiling *)
152+
Bisect_setup.init name; (* set up coverage profiling *)
178153

179154
Xenops_utils.set_fs_backend
180155
(Some (if !persist

0 commit comments

Comments
 (0)