- let ic = open_in ma_file in
- let istream = Ulexing.from_utf8_channel ic in
- let dependencies = DependenciesParser.parse_dependencies istream in
- close_in ic;
- List.iter
- (function
- | DependenciesParser.UriDep uri ->
- let uri = UriManager.string_of_uri uri in
- if not (Http_getter_storage.is_legacy uri) then
- Hashtbl.add uri_deps ma_file uri
- | DependenciesParser.BaseuriDep uri ->
- let uri = Http_getter_misc.strip_trailing_slash uri in
- Hashtbl.add baseuri_of ma_file uri
- | DependenciesParser.IncludeDep path ->
- try
- let baseuri =
- DependenciesParser.baseuri_of_script ~include_paths path in
- if not (Http_getter_storage.is_legacy baseuri) then
- let moo_file =
- LibraryMisc.obj_file_of_baseuri ~baseuri ~writable:false in
- Hashtbl.add include_deps ma_file moo_file
- with Sys_error _ ->
- HLog.warn
- ("Unable to find " ^ path ^ " that is included in " ^ ma_file)
- ) dependencies
- ) (Helm_registry.get_list Helm_registry.string "matita.args");
- Hashtbl.iter
- (fun file alias ->
- let dep = resolve alias (Hashtbl.find baseuri_of file) in
- match dep with
- | None -> ()
- | Some u ->
- Hashtbl.add include_deps file
- (LibraryMisc.obj_file_of_baseuri ~baseuri:u ~writable:false))
- uri_deps;
- List.iter
- (fun ma_file ->
- let deps = Hashtbl.find_all include_deps ma_file in
- let deps = List.fast_sort Pervasives.compare deps in
- let deps = HExtlib.list_uniq deps in
- let deps = ma_file :: deps in
- let baseuri = Hashtbl.find baseuri_of ma_file in
- let moo = LibraryMisc.obj_file_of_baseuri ~baseuri ~writable:false in
- Printf.printf "%s: %s\n" moo (String.concat " " deps);
- Printf.printf "%s: %s\n" (Pcre.replace ~pat:"ma$" ~templ:"mo" ma_file) moo)
- (Helm_registry.get_list Helm_registry.string "matita.args")
-
+ let _ = if Filename.check_suffix ma_file ".mma" then
+ let generated = Filename.chop_suffix ma_file ".mma" ^ ".ma" in
+ Hashtbl.add include_deps generated ma_file;
+ in
+ let ma_baseuri = baseuri_of_script ma_file in
+ let dependencies =
+ try DependenciesParser.deps_of_file ma_file
+ with Sys_error _ -> []
+ in
+ let handle_uri uri =
+ if not (Http_getter_storage.is_legacy uri) then
+ let dep = resolve uri ma_baseuri in
+ match dep with
+ | None -> ()
+ | Some u ->
+ match script_of_baseuri ma_file u with
+ | Some d -> Hashtbl.add include_deps ma_file d
+ | None -> ()
+ in
+ let handle_script path =
+ ignore (baseuri_of_script path);
+ Hashtbl.add include_deps ma_file path
+ in
+ List.iter
+ (function
+ | DependenciesParser.UriDep uri ->
+ let uri = UriManager.string_of_uri uri in
+ handle_uri uri
+ | DependenciesParser.InlineDep path ->
+ if Librarian.is_uri path
+ then handle_uri path else handle_script path
+ | DependenciesParser.IncludeDep path ->
+ handle_script path)
+ dependencies)
+ ma_files;
+ (* generate regular depend output *)
+(* let _ = print_times "dopo di iter2" in *)
+ let deps =
+ List.fold_left
+ (fun acc ma_file ->
+ let deps = Hashtbl.find_all include_deps ma_file in
+ let deps = List.fast_sort Pervasives.compare deps in
+ let deps = HExtlib.list_uniq deps in
+ let deps = List.map fix_name deps in
+ (fix_name ma_file, deps) :: acc)
+ [] ma_files
+ in
+ let extern =
+ List.fold_left
+ (fun acc (_,d) ->
+ List.fold_left
+ (fun a x ->
+ if List.exists (fun (t,_) -> x=t) deps then a
+ else x::a)
+ acc d)
+ [] deps
+ in
+ let where = if !use_stdout then None else Some (Sys.getcwd()) in
+ Librarian.write_deps_file where
+ (deps@HExtlib.list_uniq (List.sort Pervasives.compare (List.map (fun x ->
+ x,[]) extern)));
+ (* dot generation *)
+ if !dot_file <> "" then
+ begin
+ let oc = open_out !dot_file in
+ let fmt = Format.formatter_of_out_channel oc in
+ GraphvizPp.Dot.header fmt;
+ List.iter
+ (fun (ma_file,deps) ->
+ GraphvizPp.Dot.node ma_file fmt;
+ List.iter (fun dep -> GraphvizPp.Dot.edge ma_file dep fmt) deps)
+ deps;
+ List.iter
+ (fun x -> GraphvizPp.Dot.node ~attrs:["style","dashed"] x fmt)
+ extern;
+ GraphvizPp.Dot.trailer fmt;
+ close_out oc;
+ ignore(Sys.command ("tred "^ !dot_file^"| dot -Tpng -o"^dot_name^".png"));
+ HLog.message ("Type 'eog "^dot_name^".png' to view the graph");
+ end;
+(* let _ = print_times "fine" in () *)