Debian Codegraph @

toplevel/common_compile.ml

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 open Pp
12
13 let fatal_error msg =
14 Topfmt.std_logger Feedback.Error msg;
15 flush_all ();
16 exit 1
17
18 let warn_file_no_extension =
19 CWarnings.create ~name:"file-no-extension" ~category:CWarnings.CoreCategories.filesystem
20 (fun (f,ext) ->
21 str "File \"" ++ str f ++
22 strbrk "\" has been implicitly expanded to \"" ++
23 str f ++ str ext ++ str "\"")
24
25 let ensure_ext ext f =
26 if Filename.check_suffix f ext then f
27 else begin
28 warn_file_no_extension (f,ext);
29 f ^ ext
30 end
31
32 let safe_chop_extension f =
33 try Filename.chop_extension f with Invalid_argument _ -> f
34
35 let ensure_bname src tgt =
36 let src, tgt = Filename.basename src, Filename.basename tgt in
37 let src, tgt = safe_chop_extension src, safe_chop_extension tgt in
38 if src <> tgt then
39 fatal_error (str "Source and target file names must coincide, directories can differ" ++ fnl () ++
40 str "Source: " ++ str src ++ fnl () ++
41 str "Target: " ++ str tgt)
42
43 let ensure ~ext ~src ~tgt = ensure_bname src tgt; ensure_ext ext tgt
44
45 let ensure_exists f =
46 if not (Sys.file_exists f) then
47 fatal_error (hov 0 (str "Can't find file" ++ spc () ++ str f))
48
49 let ensure_exists_with_prefix ~src ~tgt:f_out ~src_ext ~tgt_ext =
50 let long_f_dot_src = ensure ~ext:src_ext ~src ~tgt:src in
51 ensure_exists long_f_dot_src;
52 let long_f_dot_tgt = match f_out with
53 | None -> safe_chop_extension long_f_dot_src ^ tgt_ext
54 | Some f -> ensure ~ext:tgt_ext ~src:long_f_dot_src ~tgt:f in
55 long_f_dot_src, long_f_dot_tgt
56
57 let ensure_no_pending_proofs ~filename s =
58 match s.Vernacstate.interp.lemmas with
59 | Some lemmas ->
60 let pfs = Vernacstate.LemmaStack.get_all_proof_names lemmas in
61 fatal_error (str "There are pending proofs in file " ++ str filename ++ str": "
62 ++ (pfs
63 |> List.rev
64 |> prlist_with_sep pr_comma Names.Id.print)
65 ++ str ".");
66 | None ->
67 let pm = s.Vernacstate.interp.program in
68 let what_for = Pp.str ("file " ^ filename) in
69 NeList.iter (fun pm -> Declare.Obls.check_solved_obligations ~what_for ~pm) pm