Skip to content

Commit 2c52a83

Browse files
committed
[coqdep] Minor cleanups.
- Remove inclusion of the `tactics` directory, this is coming from a time loadable modules were found there, now all are under `plugins`. - Remove 2 dependencies so we can bootstrap coqdep earlier. - Use `Format` instead of `Printf` for printing.
1 parent 6c8b00e commit 2c52a83

File tree

3 files changed

+41
-43
lines changed

3 files changed

+41
-43
lines changed

tools/coqdep.ml

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,24 @@
88
(* * (see LICENSE file for the text of the license) *)
99
(************************************************************************)
1010

11-
open Printf
11+
open Format
1212
open Coqdep_lexer
1313
open Coqdep_common
14-
open System
14+
open Minisys
1515

1616
(** The basic parts of coqdep (i.e. the parts used by [coqdep -boot])
1717
are now in [Coqdep_common]. The code that remains here concerns
1818
the other options. Calling this complete coqdep with the [-boot]
1919
option should be equivalent to calling [coqdep_boot].
20+
21+
As of today, this module depends on the following Coq modules:
22+
23+
- Flags
24+
- Envars
25+
- CoqProject_file
26+
27+
All of it for `coqlib` handling. Ideally we would like to clean
28+
coqlib handling up so this can be bootstrapped earlier.
2029
*)
2130

2231
let option_D = ref false
@@ -31,8 +40,7 @@ let warning_mult suf iter =
3140
let d' = Hashtbl.find tab f in
3241
if (Filename.dirname (file_name f d))
3342
<> (Filename.dirname (file_name f d')) then begin
34-
eprintf "*** Warning : the file %s is defined twice!\n" (f ^ suf);
35-
flush stderr
43+
coqdep_warning "the file %s is defined twice!" (f ^ suf)
3644
end
3745
with Not_found -> () end;
3846
Hashtbl.add tab f d
@@ -80,9 +88,7 @@ let mL_dep_list b f =
8088
while true do
8189
let (Use_module str) = caml_action buf in
8290
if str = b then begin
83-
eprintf "*** Warning : in file %s the" f;
84-
eprintf " notation %s. is useless !\n" b;
85-
flush stderr
91+
coqdep_warning "in file %s the notation %s. is useless !\n" f b
8692
end else
8793
if not (List.mem str !deja_vu) then addQueue deja_vu str
8894
done; []
@@ -98,16 +104,13 @@ let affiche_Declare f dcl =
98104
printf "\n*** In file %s: \n" f;
99105
printf "Declare ML Module";
100106
List.iter (fun str -> printf " \"%s\"" str) dcl;
101-
printf ".\n";
102-
flush stdout
107+
printf ".\n%!"
103108

104109
let warning_Declare f dcl =
105-
eprintf "*** Warning : in file %s, the ML modules" f;
106-
eprintf " declaration should be\n";
110+
eprintf "*** Warning : in file %s, the ML modules declaration should be\n" f;
107111
eprintf "*** Declare ML Module";
108112
List.iter (fun str -> eprintf " \"%s\"" str) dcl;
109-
eprintf ".\n";
110-
flush stderr
113+
eprintf ".\n%!"
111114

112115
let traite_Declare f =
113116
let decl_list = ref ([] : string list) in
@@ -149,7 +152,7 @@ let declare_dependencies () =
149152
List.iter
150153
(fun (name,_) ->
151154
traite_Declare (name^".v");
152-
flush stdout)
155+
pp_print_flush std_formatter ())
153156
(List.rev !vAccu)
154157

155158
(** DAGs guaranteed to be transitive reductions *)
@@ -426,11 +429,11 @@ let coq_dependencies_dump chan dumpboxes =
426429
(DAG.empty, List.fold_left (fun ih (file, _) -> insert_raw_graph file ih) [] !vAccu,
427430
List.map fst !vAccu) !vAccu
428431
in
429-
fprintf chan "digraph dependencies {\n"; flush chan;
432+
fprintf chan "digraph dependencies {\n";
430433
if dumpboxes then print_graphs chan (pop_common_prefix graphs)
431434
else List.iter (fun (name, _) -> fprintf chan "\"%s\"[label=\"%s\"]\n" name (basename_noext name)) !vAccu;
432435
DAG.iter (fun name dep -> fprintf chan "\"%s\" -> \"%s\"\n" dep name) deps;
433-
fprintf chan "}\n"
436+
fprintf chan "}\n%!"
434437

435438
end
436439

@@ -498,7 +501,7 @@ let rec parse = function
498501
| "-suffix" :: s :: ll -> suffixe := s ; parse ll
499502
| "-suffix" :: [] -> usage ()
500503
| "-slash" :: ll ->
501-
Printf.eprintf "warning: option -slash has no effect and is deprecated.\n";
504+
coqdep_warning "warning: option -slash has no effect and is deprecated.";
502505
parse ll
503506
| "-dyndep" :: "no" :: ll -> option_dynlink := No; parse ll
504507
| "-dyndep" :: "opt" :: ll -> option_dynlink := Opt; parse ll
@@ -520,7 +523,6 @@ let coqdep () =
520523
if !option_boot then begin
521524
add_rec_dir_import add_known "theories" ["Coq"];
522525
add_rec_dir_import add_known "plugins" ["Coq"];
523-
add_caml_dir "tactics";
524526
add_rec_dir_import (fun _ -> add_caml_known) "theories" ["Coq"];
525527
add_rec_dir_import (fun _ -> add_caml_known) "plugins" ["Coq"];
526528
end else begin
@@ -531,7 +533,7 @@ let coqdep () =
531533
let user = coqlib//"user-contrib" in
532534
if Sys.file_exists user then add_rec_dir_no_import add_coqlib_known user [];
533535
List.iter (fun s -> add_rec_dir_no_import add_coqlib_known s [])
534-
(Envars.xdg_dirs ~warn:(fun x -> Feedback.msg_warning (Pp.str x)));
536+
(Envars.xdg_dirs ~warn:(fun x -> coqdep_warning "%s" x));
535537
List.iter (fun s -> add_rec_dir_no_import add_coqlib_known s []) Envars.coqpath;
536538
end;
537539
List.iter (fun (f,d) -> add_mli_known f d ".mli") !mliAccu;
@@ -547,7 +549,8 @@ let coqdep () =
547549
| None -> ()
548550
| Some (box, file) ->
549551
let chan = open_out file in
550-
try Graph.coq_dependencies_dump chan box; close_out chan
552+
let chan_fmt = formatter_of_out_channel chan in
553+
try Graph.coq_dependencies_dump chan_fmt box; close_out chan
551554
with e -> close_out chan; raise e
552555
end
553556

@@ -556,4 +559,4 @@ let _ =
556559
coqdep ()
557560
with CErrors.UserError(s,p) ->
558561
let pp = (match s with | None -> p | Some s -> Pp.(str s ++ str ": " ++ p)) in
559-
Format.eprintf "%a@\n%!" Pp.pp_with pp
562+
eprintf "%a@\n%!" Pp.pp_with pp

tools/coqdep_common.ml

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
(* * (see LICENSE file for the text of the license) *)
99
(************************************************************************)
1010

11-
open Printf
12-
open Coqdep_lexer
11+
open Format
1312
open Unix
13+
open Coqdep_lexer
1414
open Minisys
1515

1616
(** [coqdep_boot] is a stripped-down version of [coqdep], whose
@@ -20,14 +20,15 @@ open Minisys
2020
options (see for instance [option_dynlink] below).
2121
*)
2222

23+
let coqdep_warning args =
24+
eprintf "*** Warning: @[";
25+
kfprintf (fun fmt -> fprintf fmt "@]\n%!") err_formatter args
26+
2327
module StrSet = Set.Make(String)
2428

2529
module StrList = struct type t = string list let compare = compare end
2630
module StrListMap = Map.Make(StrList)
2731

28-
let stderr = Pervasives.stderr
29-
let stdout = Pervasives.stdout
30-
3132
type dynlink = Opt | Byte | Both | No | Variable
3233

3334
let option_c = ref false
@@ -114,8 +115,7 @@ let same_path_opt s s' =
114115

115116
let warning_ml_clash x s suff s' suff' =
116117
if suff = suff' && not (same_path_opt s s') then
117-
eprintf
118-
"*** Warning: %s%s already found in %s (discarding %s%s)\n" x suff
118+
coqdep_warning "%s%s already found in %s (discarding %s%s)\n" x suff
119119
(match s with None -> "." | Some d -> d)
120120
((match s' with None -> "." | Some d -> d) // x) suff
121121

@@ -180,13 +180,11 @@ let error_cannot_parse s (i,j) =
180180
exit 1
181181

182182
let warning_module_notfound f s =
183-
eprintf "*** Warning: in file %s, library %s is required and has not been found in the loadpath!\n%!"
183+
coqdep_warning "in file %s, library %s is required and has not been found in the loadpath!"
184184
f (String.concat "." s)
185185

186186
let warning_declare f s =
187-
eprintf "*** Warning: in file %s, declared ML module " f;
188-
eprintf "%s has not been found!\n" s;
189-
flush stderr
187+
coqdep_warning "in file %s, declared ML module %s has not been found!" f s
190188

191189
let warning_clash file dir =
192190
match StrListMap.find dir !clash_v with
@@ -203,8 +201,7 @@ let warning_clash file dir =
203201
| _ -> assert false
204202

205203
let warning_cannot_open_dir dir =
206-
eprintf "*** Warning: cannot open %s\n" dir;
207-
flush stderr
204+
coqdep_warning "cannot open %s" dir
208205

209206
let safe_assoc from verbose file k =
210207
if verbose && StrListMap.mem k !clash_v then warning_clash file k;
@@ -451,15 +448,13 @@ let mL_dependencies () =
451448
in
452449
let efullname = escape fullname in
453450
printf "%s.cmo:%s%s\n" efullname dep intf;
454-
printf "%s.cmx:%s%s\n" efullname dep_opt intf;
455-
flush stdout)
451+
printf "%s.cmx:%s%s\n%!" efullname dep_opt intf)
456452
(List.rev !mlAccu);
457453
List.iter
458454
(fun (name,dirname) ->
459455
let fullname = file_name name dirname in
460456
let (dep,_) = traite_fichier_ML fullname ".mli" in
461-
printf "%s.cmi:%s\n" (escape fullname) dep;
462-
flush stdout)
457+
printf "%s.cmi:%s\n%!" (escape fullname) dep)
463458
(List.rev !mliAccu);
464459
List.iter
465460
(fun (name,dirname) ->
@@ -468,8 +463,7 @@ let mL_dependencies () =
468463
let efullname = escape fullname in
469464
printf "%s_MLLIB_DEPENDENCIES:=%s\n" efullname (String.concat " " dep);
470465
printf "%s.cma:$(addsuffix .cmo,$(%s_MLLIB_DEPENDENCIES))\n" efullname efullname;
471-
printf "%s.cmxa:$(addsuffix .cmx,$(%s_MLLIB_DEPENDENCIES))\n" efullname efullname;
472-
flush stdout)
466+
printf "%s.cmxa:$(addsuffix .cmx,$(%s_MLLIB_DEPENDENCIES))\n%!" efullname efullname)
473467
(List.rev !mllibAccu);
474468
List.iter
475469
(fun (name,dirname) ->
@@ -483,7 +477,7 @@ let mL_dependencies () =
483477
List.iter (fun dep ->
484478
printf "%s.cmx : FOR_PACK=-for-pack %s\n" dep efullname_capital)
485479
dep;
486-
flush stdout)
480+
printf "%!")
487481
(List.rev !mlpackAccu)
488482

489483
let coq_dependencies () =
@@ -496,8 +490,7 @@ let coq_dependencies () =
496490
printf "\n";
497491
printf "%s.vio: %s.v" ename ename;
498492
traite_fichier_Coq ".vio" true (name ^ ".v");
499-
printf "\n";
500-
flush stdout)
493+
printf "\n%!")
501494
(List.rev !vAccu)
502495

503496
let rec suffixes = function

tools/coqdep_common.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
module StrSet : Set.S with type elt = string
1212

13+
val coqdep_warning : ('a, Format.formatter, unit, unit) format4 -> 'a
14+
1315
(** [find_dir_logpath dir] Return the logical path of directory [dir]
1416
if it has been given one. Raise [Not_found] otherwise. In
1517
particular we can check if "." has been attributed a logical path

0 commit comments

Comments
 (0)