Commits

camlspotter committed c9ff307

for spotlib 2.4.0

  • Participants
  • Parent commits 630888c

Comments (0)

Files changed (1)

 open Unix
 open Printf
 
+module C = Unix.Command
+
 type dest = 
   | Package of string
   | Path of string
   let path = 
     match 
       imp_ None & fun ocamlfind_path ->
-        ignore & shell_command "ocamlfind printconf destdir" ~f: (function
-          | (`Out, `Read line) ->
-              begin match !ocamlfind_path with
-              | Some _ -> failwith "ocamlfind printconf destdir prints more than one line"
-              | None -> ocamlfind_path := Some (String.chop_newline line)
-              end
-          | _ -> ())
+        C.shell "ocamlfind printconf destdir" 
+        |> C.iter ~f: (function
+            | (`Out, `Read line) ->
+                begin match !ocamlfind_path with
+                | Some _ -> failwith "ocamlfind printconf destdir prints more than one line"
+                | None -> ocamlfind_path := Some (String.chop_newline line)
+                end
+            | _ -> ())
+        |> C.must_exit_with 0
     with
     | None -> failwith "No ocamlfind installtion path found. Check your ocamlfind."
     | Some p -> p
-  
+
   let dest_dir package = 
     match 
       imp_ None & fun result ->
-        ignore & shell_command (sprintf "ocamlfind query %s" package) ~f:(function
-          | (`Out, `Read line) ->
-              begin match !result with
-              | Some _ -> failwith "ocamlfind query package prints more than one line"
-              | None -> result := Some (String.chop_newline line)
-              end
-          | _ -> ())
+        C.shell (sprintf "ocamlfind query %s" package) 
+        |> C.iter ~f:(function
+            | (`Out, `Read line) ->
+                begin match !result with
+                | Some _ -> failwith "ocamlfind query package prints more than one line"
+                | None -> result := Some (String.chop_newline line)
+                end
+            | _ -> ())
+        |> C.must_exit_with 0
     with
     | None -> failwithf "No ocamlfind installtion path for package \"%s\" found. Check your ocamlfind." package
     | Some p -> p
     StringSet.to_list
     & imp_ StringSet.empty 
     & fun packs ->
-      ignore & shell_command "ocamlfind list" ~f:(function
-        | (`Err, `Read s) -> prerr_endline s
-        | (`Out, `Read s) ->
-            begin 
-              s |> <:m<\[(distributed with Ocaml|internal)\]>> -> () (* exclude bases *)
-                | <:m<(^[^. ]+)>> as x -> packs := StringSet.add x#_1 !packs
-                | _ -> ()
-            end
-        | _ -> ())
+        C.shell "ocamlfind list" 
+        |> C.iter ~f:(function
+            | (`Err, `Read s) -> prerr_endline s
+            | (`Out, `Read s) ->
+                begin 
+                  s |> <:m<\[(distributed with Ocaml|internal)\]>> -> () (* exclude bases *)
+                    | <:m<(^[^. ]+)>> as x -> packs := StringSet.add x#_1 !packs
+                    | _ -> ()
+                end
+            | _ -> ())
+        |> C.must_exit_with 0
 end
 
 module OCaml = struct
   let where = 
     match 
       imp_ None & fun ocaml_where ->
-        ignore & shell_command "ocamlc -where" ~f:(function
-          | (`Out, `Read line) ->
-              begin match !ocaml_where with
-              | Some _ -> failwith "ocamlc -where prints more than one line"
-              | None -> ocaml_where := Some (String.chop_newline line)
-              end
-          | _ -> ())
+        C.shell "ocamlc -where" 
+        |> C.iter ~f:(function
+            | (`Out, `Read line) ->
+                begin match !ocaml_where with
+                | Some _ -> failwith "ocamlc -where prints more than one line"
+                | None -> ocaml_where := Some (String.chop_newline line)
+                end
+            | _ -> ())
+        |> C.must_exit_with 0
     with
     | None -> failwith "ocamlc -where failed."
     | Some p -> p
         |> List.iter (fun spotspit ->
           Hashtbl.find_all installed_files (body, ext) 
           |> List.iter (fun (_package, p) -> 
-            match cmp p path#path with
+            match Shell.cmp p path#path with
             | `Different | `Error -> ()
             | `Same ->
                 (* The file is installed! If there is .spot/.spit, copy it! *)
                 let dirname = Filename.dirname p in
                 let destfile = dirname ^/ Filename.basename spotspit in 
                 let need_to_copy = 
-                  not (Sys.file_exists destfile && cmp spotspit destfile = `Same)
+                  not (Sys.file_exists destfile && Shell.cmp spotspit destfile = `Same)
                 in
                 if not need_to_copy then
                   Hashset.add copied p                
                     | `Sym  -> ["/bin/ln"; "-s"]
                   in
                   match 
-                    command (comm @ [spotspit; dirname])
-                      ~f:(function
+                    C.execvp (comm @ [spotspit; dirname])
+                    |> C.iter ~f:(function
                         | (`Err, `Read mes) -> eprintf "Failed to install %s to %s: %s\n%!" spotspit dirname mes
                         | _ -> ())
+                    |> fst
                   with
-                  | `Exited 0 -> 
+                  | Unix.WEXITED 0 -> 
                       Hashset.add copied p;
                       eprintf "Installed %s to %s\n%!" spotspit dirname
-                  | `Exited n -> 
+                  | WEXITED n -> 
                       eprintf "%s returned with a strange status %d\n%!" 
                         (String.concat " " comm)
                         n
   (* check not found *)
   Hashtbl.iter (fun _ (package, path) -> 
     if not (Hashset.mem copied path) then
-      Printf.eprintf "No binannot file found %s (%s)\n" path (show_dest package)) 
+      Printf.eprintf "No binannot file found %s (%s)\n" path (show_dest package))
     installed_files