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
(* 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
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
(* 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;
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
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)