Skip to content

Commit 802366b

Browse files
committed
coqc: support -o option to specify output file name
The -o option lets one put .vo or .vio files in a directory of choice, i.e. decouple the location of the sources and the compiled files. This ease the integration of Coq in already existing IDEs that handle the build process automatically (eg Eclipse) and also enables one to compile/run at the same time 2 versions of Coq on the same sources. Example: b.v depending on a.v coq8.6/bin/coqc -R out8.6 Test src/a.v -o out8.6/a.vo coq8.6/bin/coqc -R out8.6 Test src/b.v -o out8.6/b.vo coq8.7/bin/coqc -R out8.7 Test src/a.v -o out8.7/a.vo coq8.7/bin/coqc -R out8.7 Test src/b.v -o out8.7/b.vo
1 parent f7fb191 commit 802366b

File tree

11 files changed

+68
-29
lines changed

11 files changed

+68
-29
lines changed

lib/aux_file.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ let mk_absolute vfile =
2525
if Filename.is_relative vfile then CUnix.correct_path vfile (Sys.getcwd ())
2626
else vfile
2727

28-
let start_aux_file_for vfile =
29-
let vfile = mk_absolute vfile in
30-
oc := Some (open_out (aux_file_name_for vfile));
28+
let start_aux_file ~aux_file:output_file ~v_file =
29+
let vfile = mk_absolute v_file in
30+
oc := Some (open_out output_file);
3131
Printf.fprintf (Option.get !oc) "COQAUX%d %s %s\n"
3232
version (Digest.to_hex (Digest.file vfile)) vfile
3333

lib/aux_file.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ module H : Map.S with type key = int * int
1717
module M : Map.S with type key = string
1818
val contents : aux_file -> string M.t H.t
1919

20-
val start_aux_file_for : string -> unit
20+
val aux_file_name_for : string -> string
21+
val start_aux_file : aux_file:string -> v_file:string -> unit
2122
val stop_aux_file : unit -> unit
2223
val recording : unit -> bool
2324

lib/flags.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ let batch_mode = ref false
4747

4848
type compilation_mode = BuildVo | BuildVio | Vio2Vo
4949
let compilation_mode = ref BuildVo
50+
let compilation_output_name = ref None
5051

5152
let test_mode = ref false
5253

lib/flags.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ val load_init : bool ref
1414
val batch_mode : bool ref
1515
type compilation_mode = BuildVo | BuildVio | Vio2Vo
1616
val compilation_mode : compilation_mode ref
17+
val compilation_output_name : string option ref
1718

1819
val test_mode : bool ref
1920

library/library.ml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -628,17 +628,14 @@ let check_module_name s =
628628
done
629629
| c -> err c
630630

631-
let start_library f =
632-
let () = if not (Sys.file_exists f) then
633-
errorlabstrm "" (hov 0 (str "Can't find file" ++ spc () ++ str f))
634-
in
631+
let start_library fo =
635632
let ldir0 =
636633
try
637-
let lp = Loadpath.find_load_path (Filename.dirname f) in
634+
let lp = Loadpath.find_load_path (Filename.dirname fo) in
638635
Loadpath.logical lp
639636
with Not_found -> Nameops.default_root_prefix
640637
in
641-
let file = Filename.chop_extension (Filename.basename f) in
638+
let file = Filename.chop_extension (Filename.basename fo) in
642639
let id = Id.of_string file in
643640
check_module_name file;
644641
check_coq_overwriting ldir0 id;
@@ -693,12 +690,13 @@ let error_recursively_dependent_library dir =
693690
writing the content and computing the checksum... *)
694691

695692
let save_library_to ?todo dir f otab =
696-
let f, except = match todo with
693+
let except = match todo with
697694
| None ->
698695
assert(!Flags.compilation_mode = Flags.BuildVo);
699-
f ^ "o", Future.UUIDSet.empty
696+
assert(Filename.check_suffix f ".vo");
697+
Future.UUIDSet.empty
700698
| Some (l,_) ->
701-
f ^ "io",
699+
assert(Filename.check_suffix f ".vio");
702700
List.fold_left (fun e (r,_) -> Future.UUIDSet.add r.Stateid.uuid e)
703701
Future.UUIDSet.empty l in
704702
let cenv, seg, ast = Declaremods.end_library ~except dir in

library/library.mli

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ type seg_proofs = Term.constr Future.computation array
3737
an export otherwise just a simple import *)
3838
val import_module : bool -> qualid located list -> unit
3939

40-
(** Start the compilation of a file as a library. The argument must be an
41-
existing file on the system, and the returned path is the associated
42-
absolute logical path of the library. *)
40+
(** Start the compilation of a file as a library. The first argument must be
41+
output file, and the
42+
returned path is the associated absolute logical path of the library. *)
4343
val start_library : CUnix.physical_path -> DirPath.t
4444

4545
(** End the compilation of a library and save it to a ".vo" file *)

stm/stm.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,11 +2108,11 @@ let handle_failure (e, info) vcs tty =
21082108
VCS.print ();
21092109
iraise (e, info)
21102110

2111-
let snapshot_vio ldir long_f_dot_v =
2111+
let snapshot_vio ldir long_f_dot_vo =
21122112
finish ();
21132113
if List.length (VCS.branches ()) > 1 then
21142114
Errors.errorlabstrm "stm" (str"Cannot dump a vio with open proofs");
2115-
Library.save_library_to ~todo:(dump_snapshot ()) ldir long_f_dot_v
2115+
Library.save_library_to ~todo:(dump_snapshot ()) ldir long_f_dot_vo
21162116
(Global.opaque_tables ())
21172117

21182118
let reset_task_queue = Slaves.reset_task_queue

tools/coqc.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ let parse_args () =
107107
|"-load-ml-source"|"-require"|"-load-ml-object"
108108
|"-init-file"|"-dump-glob"|"-compat"|"-coqlib"|"-top"
109109
|"-async-proofs-j" |"-async-proofs-private-flags" |"-async-proofs" |"-w"
110+
|"-o"
110111
as o) :: rem ->
111112
begin
112113
match rem with

toplevel/coqtop.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ let parse_args arglist =
514514
|"-vio2vo" -> add_compile false (next ()); Flags.compilation_mode := Vio2Vo
515515
|"-toploop" -> set_toploop (next ())
516516
|"-w" -> set_warning (next ())
517+
|"-o" -> Flags.compilation_output_name := Some (next())
517518

518519
(* Options with zero arg *)
519520
|"-async-queries-always-delegate"

toplevel/usage.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ let print_usage_channel co command =
4545
\n -require path load Coq library path and import it (Require Import path.)\
4646
\n -compile f.v compile Coq file f.v (implies -batch)\
4747
\n -compile-verbose f.v verbosely compile Coq file f.v (implies -batch)\
48+
\n -o f.vo use f.vo as the output file name\
4849
\n -quick quickly compile .v files to .vio files (skip proofs)\
4950
\n -schedule-vio2vo j f1..fn run up to j instances of Coq to turn each fi.vio\
5051
\n into fi.vo\

0 commit comments

Comments
 (0)