1 (* Copyright (C) 2005, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
28 module GA = GrafiteAst
31 let obj_file_of_baseuri writable baseuri =
33 LibraryMisc.obj_file_of_baseuri
34 ~must_exist:true ~baseuri ~writable
36 | Http_getter_types.Unresolvable_URI _
37 | Http_getter_types.Key_not_found _ ->
38 LibraryMisc.obj_file_of_baseuri
39 ~must_exist:false ~baseuri ~writable:true
43 (* all are maps from "file" to "something" *)
44 let include_deps = Hashtbl.create (Array.length Sys.argv) in
45 let baseuri_of = Hashtbl.create (Array.length Sys.argv) in
46 let uri_deps = Hashtbl.create (Array.length Sys.argv) in
47 let buri alias = U.buri_of_uri (U.uri_of_string alias) in
48 let resolve alias current_buri =
49 let buri = buri alias in
50 if buri <> current_buri then Some buri else None in
51 MatitaInit.fill_registry ();
52 MatitaInit.parse_cmdline ();
53 MatitaInit.load_configuration_file ();
55 Helm_registry.get_list Helm_registry.string "matita.includes" in
58 let ic = open_in ma_file in
59 let istream = Ulexing.from_utf8_channel ic in
60 let dependencies = DependenciesParser.parse_dependencies istream in
64 | DependenciesParser.UriDep uri ->
65 let uri = UriManager.string_of_uri uri in
66 if not (Http_getter_storage.is_legacy uri) then
67 Hashtbl.add uri_deps ma_file uri
68 | DependenciesParser.BaseuriDep uri ->
69 let uri = Http_getter_misc.strip_trailing_slash uri in
70 Hashtbl.add baseuri_of ma_file uri
71 | DependenciesParser.IncludeDep path ->
74 DependenciesParser.baseuri_of_script ~include_paths path in
75 if not (Http_getter_storage.is_legacy baseuri) then
76 let moo_file = obj_file_of_baseuri false baseuri in
77 Hashtbl.add include_deps ma_file moo_file
80 ("Unable to find " ^ path ^ " that is included in " ^ ma_file)
82 ) (Helm_registry.get_list Helm_registry.string "matita.args");
85 let dep = resolve alias (Hashtbl.find baseuri_of file) in
89 Hashtbl.add include_deps file (obj_file_of_baseuri false u))
93 let deps = Hashtbl.find_all include_deps ma_file in
94 let deps = List.fast_sort Pervasives.compare deps in
95 let deps = HExtlib.list_uniq deps in
96 let deps = ma_file :: deps in
97 let baseuri = Hashtbl.find baseuri_of ma_file in
98 let moo = obj_file_of_baseuri true baseuri in
99 Printf.printf "%s: %s\n%s: %s\n%s: %s\n" moo (String.concat " " deps)
100 (Filename.basename (Pcre.replace ~pat:"ma$" ~templ:"mo" ma_file)) moo
101 (Pcre.replace ~pat:"ma$" ~templ:"mo" ma_file) moo)
102 (Helm_registry.get_list Helm_registry.string "matita.args")