2002-03-27 08:20:32 -08:00
|
|
|
(***********************************************************************)
|
2012-08-01 05:09:31 -07:00
|
|
|
(* *)
|
2002-03-27 08:20:32 -08:00
|
|
|
(* OCamldoc *)
|
|
|
|
(* *)
|
|
|
|
(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 2001 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
2010-08-24 04:48:46 -07:00
|
|
|
(** Main module for bytecode.
|
2015-10-09 13:41:51 -07:00
|
|
|
@todo todo*)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
open Config
|
|
|
|
open Clflags
|
|
|
|
open Misc
|
|
|
|
open Format
|
|
|
|
open Typedtree
|
|
|
|
|
2004-01-28 05:36:20 -08:00
|
|
|
module M = Odoc_messages
|
|
|
|
|
2006-09-20 04:14:37 -07:00
|
|
|
let print_DEBUG s = print_string s ; print_newline ()
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(* we check if we must load a module given on the command line *)
|
|
|
|
let arg_list = Array.to_list Sys.argv
|
2010-08-24 04:48:46 -07:00
|
|
|
let (plugins, paths) =
|
|
|
|
let rec iter (files, incs) = function
|
|
|
|
[] | _ :: [] -> (List.rev files, List.rev incs)
|
2002-03-27 08:20:32 -08:00
|
|
|
| "-g" :: file :: q when
|
2013-05-28 04:04:11 -07:00
|
|
|
((Filename.check_suffix file "cmo") ||
|
|
|
|
(Filename.check_suffix file "cma") ||
|
2010-08-24 04:48:46 -07:00
|
|
|
(Filename.check_suffix file "cmxs")) ->
|
|
|
|
iter (file :: files, incs) q
|
2009-03-11 00:04:39 -07:00
|
|
|
| "-i" :: dir :: q ->
|
2010-08-24 04:48:46 -07:00
|
|
|
iter (files, dir :: incs) q
|
2009-03-11 00:04:39 -07:00
|
|
|
| _ :: q ->
|
2010-08-24 04:48:46 -07:00
|
|
|
iter (files, incs) q
|
2002-03-27 08:20:32 -08:00
|
|
|
in
|
2010-08-24 04:48:46 -07:00
|
|
|
iter ([], []) arg_list
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
let _ = print_DEBUG "Fin analyse des arguments pour le dynamic load"
|
|
|
|
|
2006-09-20 04:14:37 -07:00
|
|
|
(** Return the real name of the file to load,
|
2004-01-28 05:36:20 -08:00
|
|
|
searching it in the paths if it is
|
|
|
|
a simple name and not in the current directory. *)
|
|
|
|
let get_real_filename name =
|
|
|
|
if Filename.basename name <> name then
|
|
|
|
name
|
|
|
|
else
|
|
|
|
(
|
2004-07-13 05:25:21 -07:00
|
|
|
let paths = Filename.current_dir_name :: paths @ [Odoc_config.custom_generators_path] in
|
2004-01-28 05:36:20 -08:00
|
|
|
try
|
2010-01-22 04:48:24 -08:00
|
|
|
let d = List.find
|
|
|
|
(fun d -> Sys.file_exists (Filename.concat d name))
|
|
|
|
paths
|
|
|
|
in
|
|
|
|
Filename.concat d name
|
2004-01-28 05:36:20 -08:00
|
|
|
with
|
2010-01-22 04:48:24 -08:00
|
|
|
Not_found ->
|
|
|
|
failwith (M.file_not_found_in_paths paths name)
|
2004-01-28 05:36:20 -08:00
|
|
|
)
|
|
|
|
|
2010-08-24 04:48:46 -07:00
|
|
|
let load_plugin file =
|
|
|
|
let file = Dynlink.adapt_filename file in
|
|
|
|
Dynlink.allow_unsafe_modules true;
|
|
|
|
try
|
|
|
|
let real_file = get_real_filename file in
|
|
|
|
ignore(Dynlink.loadfile real_file)
|
|
|
|
with
|
|
|
|
Dynlink.Error e ->
|
|
|
|
prerr_endline (Odoc_messages.load_file_error file (Dynlink.error_message e)) ;
|
|
|
|
exit 1
|
|
|
|
| Not_found ->
|
|
|
|
prerr_endline (Odoc_messages.load_file_error file "Not_found");
|
|
|
|
exit 1
|
|
|
|
| Sys_error s
|
|
|
|
| Failure s ->
|
|
|
|
prerr_endline (Odoc_messages.load_file_error file s);
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
List.iter load_plugin plugins;;
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2010-08-24 02:45:45 -07:00
|
|
|
let () = print_DEBUG "Fin du chargement dynamique eventuel"
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2010-08-24 02:45:45 -07:00
|
|
|
let () = Odoc_args.parse ()
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
|
|
|
|
let loaded_modules =
|
2006-09-20 04:14:37 -07:00
|
|
|
List.flatten
|
|
|
|
(List.map
|
2002-03-27 08:20:32 -08:00
|
|
|
(fun f ->
|
2002-07-23 07:12:03 -07:00
|
|
|
Odoc_info.verbose (Odoc_messages.loading f);
|
2006-09-20 04:14:37 -07:00
|
|
|
try
|
2002-07-23 07:12:03 -07:00
|
|
|
let l = Odoc_analyse.load_modules f in
|
|
|
|
Odoc_info.verbose Odoc_messages.ok;
|
|
|
|
l
|
2006-09-20 04:14:37 -07:00
|
|
|
with Failure s ->
|
|
|
|
prerr_endline s ;
|
2002-07-23 07:12:03 -07:00
|
|
|
incr Odoc_global.errors ;
|
|
|
|
[]
|
2002-03-27 08:20:32 -08:00
|
|
|
)
|
2010-08-24 02:45:45 -07:00
|
|
|
!Odoc_global.load
|
2002-03-27 08:20:32 -08:00
|
|
|
)
|
|
|
|
|
2010-08-24 02:45:45 -07:00
|
|
|
let modules = Odoc_analyse.analyse_files ~init: loaded_modules !Odoc_global.files
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
let _ =
|
2010-08-24 02:45:45 -07:00
|
|
|
match !Odoc_global.dump with
|
2002-03-27 08:20:32 -08:00
|
|
|
None -> ()
|
|
|
|
| Some f ->
|
|
|
|
try Odoc_analyse.dump_modules f modules
|
2006-09-20 04:14:37 -07:00
|
|
|
with Failure s ->
|
2002-07-23 07:12:03 -07:00
|
|
|
prerr_endline s ;
|
|
|
|
incr Odoc_global.errors
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2010-08-24 02:45:45 -07:00
|
|
|
|
2006-09-20 04:14:37 -07:00
|
|
|
let _ =
|
2010-08-24 02:45:45 -07:00
|
|
|
match !Odoc_args.current_generator with
|
2002-03-27 08:20:32 -08:00
|
|
|
None ->
|
|
|
|
()
|
2006-09-20 04:14:37 -07:00
|
|
|
| Some gen ->
|
2010-08-24 02:45:45 -07:00
|
|
|
let generator = Odoc_gen.get_minimal_generator gen in
|
2002-03-27 08:20:32 -08:00
|
|
|
Odoc_info.verbose Odoc_messages.generating_doc;
|
2010-08-24 02:45:45 -07:00
|
|
|
generator#generate modules;
|
2002-03-27 08:20:32 -08:00
|
|
|
Odoc_info.verbose Odoc_messages.ok
|
|
|
|
|
2006-09-20 04:14:37 -07:00
|
|
|
let _ =
|
2002-03-27 08:20:32 -08:00
|
|
|
if !Odoc_global.errors > 0 then
|
|
|
|
(
|
|
|
|
prerr_endline (Odoc_messages.errors_occured !Odoc_global.errors) ;
|
|
|
|
exit 1
|
|
|
|
)
|
|
|
|
else
|
|
|
|
exit 0
|