]> matita.cs.unibo.it Git - helm.git/blobdiff - components/library/librarian.ml
fixed two preblems in matitadep, one coming from the dep-parser and
[helm.git] / components / library / librarian.ml
index f1649239460939d2915f226bc38b90312df3e82d..cc3c96999453a8e88d1b42560c550acc347f3a0e 100644 (file)
@@ -38,10 +38,11 @@ let remove_trailing_slash s =
 let load_root_file rootpath =
   let data = HExtlib.input_file rootpath in
   let lines = Str.split (Str.regexp "\n") data in
+  let clean s = Pcre.replace ~pat:"^ *" (Pcre.replace ~pat:" *$" s) in
   List.map 
     (fun l -> 
       match Str.split (Str.regexp "=") l with
-      | [k;v] -> Pcre.replace ~pat:" " k, Pcre.replace ~pat:" " v
+      | [k;v] -> clean k, Http_getter_misc.strip_trailing_slash (clean v)
       | _ -> raise (Failure ("Malformed root file: " ^ rootpath)))
     lines
 ;;
@@ -51,7 +52,7 @@ let find_root_for ~include_paths file =
  try 
    let path = HExtlib.find_in include_paths file in
    let path = absolutize path in
-   (* HLog.debug ("file "^file^" resolved as "^path); *)
+(*     HLog.debug ("file "^file^" resolved as "^path);  *)
    let rootpath, root, buri = 
      try
        let mburi = Helm_registry.get "matita.baseuri" in
@@ -64,14 +65,16 @@ let find_root_for ~include_paths file =
        let buri = List.assoc "baseuri" (load_root_file rootpath) in
        rootpath, Filename.dirname rootpath, buri
    in
-   (* HLog.debug ("file "^file^" rooted by "^rootpath^""); *)
+(*     HLog.debug ("file "^file^" rooted by "^rootpath^"");  *)
    let uri = Http_getter_misc.strip_trailing_slash buri in
    if String.length uri < 5 || String.sub uri 0 5 <> "cic:/" then
      HLog.error (rootpath ^ " sets an incorrect baseuri: " ^ buri);
    ensure_trailing_slash root, remove_trailing_slash uri, path
- with Failure "find_in" as exn -> 
-   HLog.error ("Unable to find: "^file);
-   raise exn
+ with Failure "find_in" -> 
+   HLog.error ("We are in: " ^ Sys.getcwd ());
+   HLog.error ("Unable to find: "^file^"\nPaths explored:");
+   List.iter (fun x -> HLog.error (" - "^x)) include_paths;
+   raise (NoRootFor file)
 ;;
 
 let baseuri_of_script ~include_paths file = 
@@ -117,7 +120,9 @@ let load_deps_file f =
       begin
         let l = input_line ic in
         match Str.split (Str.regexp " ") l with
-        | [] -> HLog.error ("malformed deps file: " ^ f); exit 1
+        | [] -> 
+            HLog.error ("Malformed deps file: " ^ f); 
+            raise (Failure ("Malformed deps file: " ^ f)) 
         | he::tl -> deps := (he,tl) :: !deps
       end
     done; !deps
@@ -240,7 +245,8 @@ module Make = functor (F:Format) -> struct
         let todo =
           let local, remote =
             List.partition
-              (fun (file,d) -> d<>[] || F.root_of local_options file = Some root)
+              (fun (file,d) -> 
+                d<>[] || F.root_of local_options file = Some root)
               todo
           in
           remote @ local
@@ -255,7 +261,7 @@ module Make = functor (F:Format) -> struct
               | Some froot ->
                   make froot [file]
               | None -> 
-                  HLog.error ("No root for: "^F.string_of_source_object file);            
+                  HLog.error ("No root for: "^F.string_of_source_object file);
                   false
             in
             if rc then (file::c,f)
@@ -286,9 +292,11 @@ module Make = functor (F:Format) -> struct
 end
   
 let write_deps_file root deps =
-  let oc = open_out "depends" in
-  List.iter (fun (t,d) -> output_string oc (t^" "^String.concat " " d^"\n")) deps;
+  let oc = open_out (root ^ "/depends") in
+  List.iter 
+    (fun (t,d) -> output_string oc (t^" "^String.concat " " d^"\n")) 
+    deps;
   close_out oc;
-  HLog.message ("Generated " ^ Sys.getcwd () ^ "/depends")
+  HLog.message ("Generated: " ^ root ^ "/depends")
 ;;