Skip to content

Commit

Permalink
Add rocq dep subcommand, move coqdep back to coq-core
Browse files Browse the repository at this point in the history
  • Loading branch information
SkySkimmer committed Dec 9, 2024
1 parent 6bc3229 commit ed28115
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 60 deletions.
58 changes: 1 addition & 57 deletions tools/coqdep/coqdep.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,4 @@
(* * (see LICENSE file for the text of the license) *)
(************************************************************************)

(** The basic parts of coqdep are in [Common]. *)
open Coqdeplib

let warn_home_dir =
let category = CWarnings.CoreCategories.filesystem in
CWarnings.create ~name:"cannot-locate-home-dir" ~category Pp.str

let coqdep () =
let open Common in

ignore (Feedback.(add_feeder (console_feedback_listener Format.err_formatter)));

(* Initialize coqdep, add files to dependency computation *)
if Array.length Sys.argv < 2 then Args.usage ();
let args =
Sys.argv
|> Array.to_list
|> List.tl
|> Args.parse (Args.make ())
in
let v_files = args.Args.files in
(* We are in makefile hack mode *)
let make_separator_hack = true in
let st = init ~make_separator_hack args in
let lst = Common.State.loadpath st in
List.iter treat_file_command_line v_files;

(* XXX: All the code below is just setting loadpaths, refactor to
Common coq.boot library *)
(* Add current dir with empty logical path if not set by options above. *)
(try ignore (Loadpath.find_dir_logpath (Sys.getcwd()))
with Not_found -> Loadpath.add_norec_dir_import (Loadpath.add_known lst) "." []);
(* We don't setup any loadpath if the -boot is passed *)
if not args.Args.boot then begin
let env = Boot.Env.init () in
let stdlib = Boot.Env.(stdlib env |> Path.to_string) in
let plugins = Boot.Env.(plugins env |> Path.to_string) in
let user_contrib = Boot.Env.(user_contrib env |> Path.to_string) in
Loadpath.add_rec_dir_import (Loadpath.add_coqlib_known lst) stdlib ["Corelib"];
Loadpath.add_rec_dir_import (Loadpath.add_coqlib_known lst) plugins ["Corelib"];
if Sys.file_exists user_contrib then
Loadpath.add_rec_dir_no_import (Loadpath.add_coqlib_known lst) user_contrib [];
let add_dir s = Loadpath.add_rec_dir_no_import (Loadpath.add_coqlib_known lst) s [] in
List.iter add_dir (Envars.xdg_dirs ~warn:warn_home_dir);
List.iter add_dir Envars.coqpath
end;
if args.Args.sort then
sort st
else
compute_deps st |> List.iter (Makefile.print_dep Format.std_formatter)

let () =
try
coqdep ()
with exn ->
Format.eprintf "*** Error: @[%a@]@\n%!" Pp.pp_with (CErrors.print exn);
exit 1
let () = Coqdeplib.Rocqdep_main.main (List.tl (Array.to_list Sys.argv))
3 changes: 1 addition & 2 deletions tools/coqdep/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
(executable
(name coqdep)
(public_name coqdep)
(package rocq-runtime)
(modes exe byte)
(package coq-core)
(modules coqdep)
(libraries coqdeplib))
61 changes: 61 additions & 0 deletions tools/coqdep/lib/rocqdep_main.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
(************************************************************************)
(* * The Rocq Prover / The Rocq Development Team *)
(* v * Copyright INRIA, CNRS and contributors *)
(* <O___,, * (see version control and CREDITS file for authors & dates) *)
(* \VV/ **************************************************************)
(* // * This file is distributed under the terms of the *)
(* * GNU Lesser General Public License Version 2.1 *)
(* * (see LICENSE file for the text of the license) *)
(************************************************************************)

(** The basic parts of coqdep are in [Common]. *)

let warn_home_dir =
let category = CWarnings.CoreCategories.filesystem in
CWarnings.create ~name:"cannot-locate-home-dir" ~category Pp.str

let coqdep args =
let open Common in

ignore (Feedback.(add_feeder (console_feedback_listener Format.err_formatter)));

(* Initialize coqdep, add files to dependency computation *)
if CList.is_empty args then Args.usage ();
let args = Args.parse (Args.make ()) args in
let v_files = args.Args.files in
(* We are in makefile hack mode *)
let make_separator_hack = true in
let st = init ~make_separator_hack args in
let lst = Common.State.loadpath st in
List.iter treat_file_command_line v_files;

(* XXX: All the code below is just setting loadpaths, refactor to
Common coq.boot library *)
(* Add current dir with empty logical path if not set by options above. *)
(try ignore (Loadpath.find_dir_logpath (Sys.getcwd()))
with Not_found -> Loadpath.add_norec_dir_import (Loadpath.add_known lst) "." []);
(* We don't setup any loadpath if the -boot is passed *)
if not args.Args.boot then begin
let env = Boot.Env.init () in
let stdlib = Boot.Env.(stdlib env |> Path.to_string) in
let plugins = Boot.Env.(plugins env |> Path.to_string) in
let user_contrib = Boot.Env.(user_contrib env |> Path.to_string) in
Loadpath.add_rec_dir_import (Loadpath.add_coqlib_known lst) stdlib ["Corelib"];
Loadpath.add_rec_dir_import (Loadpath.add_coqlib_known lst) plugins ["Corelib"];
if Sys.file_exists user_contrib then
Loadpath.add_rec_dir_no_import (Loadpath.add_coqlib_known lst) user_contrib [];
let add_dir s = Loadpath.add_rec_dir_no_import (Loadpath.add_coqlib_known lst) s [] in
List.iter add_dir (Envars.xdg_dirs ~warn:warn_home_dir);
List.iter add_dir Envars.coqpath
end;
if args.Args.sort then
sort st
else
compute_deps st |> List.iter (Makefile.print_dep Format.std_formatter)

let main args =
try
coqdep args
with exn ->
Format.eprintf "*** Error: @[%a@]@\n%!" Pp.pp_with (CErrors.print exn);
exit 1
11 changes: 11 additions & 0 deletions tools/coqdep/lib/rocqdep_main.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(************************************************************************)
(* * The Rocq Prover / The Rocq Development Team *)
(* v * Copyright INRIA, CNRS and contributors *)
(* <O___,, * (see version control and CREDITS file for authors & dates) *)
(* \VV/ **************************************************************)
(* // * This file is distributed under the terms of the *)
(* * GNU Lesser General Public License Version 2.1 *)
(* * (see LICENSE file for the text of the license) *)
(************************************************************************)

val main : string list -> unit
2 changes: 1 addition & 1 deletion topbin/dune
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
(modules rocq)
(modes exe byte)
; we statically link the "small" subcommands instead of having separate binaries
(libraries rocqshim coqpp))
(libraries rocqshim coqdeplib coqpp))

(install
(section bin)
Expand Down
1 change: 1 addition & 0 deletions topbin/rocq.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ let () =
| ("c" | "compile") :: args -> with_worker opts "compile" args
| ("top"|"repl") :: args -> with_worker opts "repl" args
| ("preprocess-mlg"|"pp-mlg") :: args -> Coqpp_main.main args
| "dep" :: args -> Coqdeplib.Rocqdep_main.main args

| prog :: _ ->
fatal_error "Unknown argument %s" prog
Expand Down

0 comments on commit ed28115

Please sign in to comment.