]> matita.cs.unibo.it Git - helm.git/blobdiff - matita/matitamakeLib.ml
fast and sound registry lists
[helm.git] / matita / matitamakeLib.ml
index 4544f9ada5c6f99ebeb23131609b1103d433f584..499d0eaf361938c9bd363d7f72e8d7bbf0118f2f 100644 (file)
@@ -42,6 +42,21 @@ let developments = ref []
 let pool () = Helm_registry.get "matita.basedir" ^ "/matitamake/" ;;
 let rootfile = "/root" ;;
 
+(* /foo/./bar/..//baz -> /foo/baz *)
+let normalize_path s = 
+  let s = Str.global_replace (Str.regexp "//") "/" s in
+  let l = Str.split (Str.regexp "/") s in
+  let rec aux = function
+    | [] -> []
+    | he::".."::tl -> aux tl
+    | he::"."::tl -> aux (he::tl)
+    | he::tl -> he :: aux tl
+  in
+  (if Str.string_match (Str.regexp "^/") s 0 then "/" else "") ^
+  String.concat "/" (aux l)
+  ^ (if Str.string_match (Str.regexp "/$") s 0 then "/" else "")
+;;
+
 let ls_dir dir = 
   try
     let d = Unix.opendir dir in
@@ -63,25 +78,26 @@ let initialize () =
   match ls_dir (pool ()) with
   | None -> logger `Error ("Unable to list directory " ^ pool ()) 
   | Some l -> 
-      List.iter 
-        (fun name -> 
-          let root = 
-            try 
-              Some (HExtlib.input_file (pool () ^ name ^ rootfile))
-            with Unix.Unix_error _ -> 
-              logger `Warning ("Malformed development " ^ name);
-              None
-          in 
-          match root with 
-          | None -> ()
-          | Some root -> 
-              developments := {root = root ; name = name} :: !developments;
-              let inc = Helm_registry.get_list 
-                Helm_registry.string "matita.includes" in
-              Helm_registry.set_list Helm_registry.of_string 
-                ~key:"matita.includes" ~value:(inc @ [root])
-          ) 
-      l
+      let paths = 
+        List.fold_left 
+          (fun acc name -> 
+            let root = 
+              try 
+                Some (HExtlib.input_file (pool () ^ name ^ rootfile))
+              with Unix.Unix_error _ -> 
+                logger `Warning ("Malformed development " ^ name);
+                None
+            in 
+            match root with 
+            | None -> acc
+            | Some root -> 
+                developments := {root = root ; name = name} :: !developments;
+                root::acc)
+         [] l
+      in
+      let inc = Helm_registry.get_list Helm_registry.string "matita.includes" in
+      Helm_registry.set_list Helm_registry.of_string 
+        ~key:"matita.includes" ~value:(inc @ paths)
 
 (* finds the makefile path for development devel *)
 let makefile_for_development devel =
@@ -94,6 +110,7 @@ let dot_for_development devel =
 
 (* given a dir finds a development that is radicated in it or below *)
 let development_for_dir dir =
+  let dir = normalize_path dir in
   let is_prefix_of d1 d2 =
     let len1 = String.length d1 in
     let len2 = String.length d2 in
@@ -130,9 +147,14 @@ let rebuild_makefile development =
     HExtlib.input_file BuildTimeConf.matitamake_makefile_template 
   in
   let ext = Lazy.force am_i_opt in
-  let cc = BuildTimeConf.runtime_base_dir ^ "/matitac" ^ ext in
-  let rm = BuildTimeConf.runtime_base_dir ^ "/matitaclean" ^ ext in
-  let mm = BuildTimeConf.runtime_base_dir ^ "/matitadep" ^ ext in
+  let binpath = 
+    if HExtlib.is_executable 
+      (BuildTimeConf.runtime_base_dir ^ "/matitac" ^ ext)
+    then BuildTimeConf.runtime_base_dir ^ "/" else ""
+  in
+  let cc = binpath ^ "matitac" ^ ext in
+  let rm = binpath ^ "matitaclean" ^ ext in
+  let mm = binpath ^ "matitadep" ^ ext in
   let df = pool () ^ development.name ^ "/depend" in
   let template = Pcre.replace ~pat:"@ROOT@" ~templ:development.root template in
   let template = Pcre.replace ~pat:"@CC@" ~templ:cc template in
@@ -157,6 +179,7 @@ let rebuild_makefile_devel development =
   
 (* creates a new development if possible *)
 let initialize_development name dir =
+  let dir = normalize_path dir in
   let name = Pcre.replace ~pat:" " ~templ:"_" name in 
   let dev = {name = name ; root = dir} in
   dump_development dev;
@@ -187,20 +210,24 @@ let call_make ?matita_flags development target make =
       | None -> (try Sys.getenv "MATITA_FLAGS" with Not_found -> "")
       | Some s -> s 
     in
-    already_defined ^ 
-      if Helm_registry.get_bool "matita.bench" then "-bench" else ""
+    let bench = 
+      if Helm_registry.get_bool "matita.bench" then " -bench" else ""
+    in
+    let system = 
+      if Helm_registry.get_bool "matita.system" then " -system" else ""
+    in
+    let noinnertypes = 
+      if Helm_registry.get_bool "matita.noinnertypes" then " -noinnertypes" else ""
+    in
+    already_defined ^ bench ^ system ^ noinnertypes
   in
   let csc = try ["SRC=" ^ Sys.getenv "SRC"] with Not_found -> [] in
   rebuild_makefile development;
   let makefile = makefile_for_development development in
-  let nodb =
-    Helm_registry.get_opt_default Helm_registry.bool ~default:false "db.nodb"
-  in
   let flags = [] in 
-  let flags = flags @ if nodb then ["NODB=true"] else [] in
   let flags =
     try
-      flags @ [ sprintf "MATITA_FLAGS=\"%s\"" matita_flags ]
+      flags @ [ sprintf "MATITA_FLAGS=%s" matita_flags ]
     with Not_found -> flags in
   let flags = flags @ csc in
   let args = 
@@ -247,7 +274,7 @@ let mk_maker refresh_cb =
     let out_r,out_w = Unix.pipe () in
     let err_r,err_w = Unix.pipe () in
     let pid = ref ~-1 in
-    ignore(Sys.signal Sys.sigchld (Sys.Signal_ignore));
+    let oldhandler = Sys.signal Sys.sigchld (Sys.Signal_ignore) in
     try
 (*       prerr_endline (String.concat " " args); *)
       let argv = Array.of_list ("make"::args) in
@@ -271,10 +298,13 @@ let mk_maker refresh_cb =
         aux r;
         refresh_cb ()
       done;
+      ignore(Sys.signal Sys.sigchld oldhandler);
       true
     with 
     | Unix.Unix_error (_,"read",_)
-    | Unix.Unix_error (_,"select",_) -> true)
+    | Unix.Unix_error (_,"select",_) -> 
+        ignore(Sys.signal Sys.sigchld oldhandler);
+        true)
 
 let build_development_in_bg ?matita_flags ?(target="all") refresh_cb development =
   call_make ?matita_flags development target (mk_maker refresh_cb)
@@ -329,7 +359,7 @@ let publish_development_bstract build clean devel =
     let orig_matita_flags = 
       try Sys.getenv "MATITA_FLAGS" with Not_found -> "" 
     in
-    "\"" ^ orig_matita_flags ^ "\"", "\"" ^ orig_matita_flags ^ " -system\"
+    orig_matita_flags, orig_matita_flags ^ " -system
   in
   HLog.message "cleaning the development before publishing";
   if clean ~matita_flags devel then