Commits

camlspotter committed 3cf2069

support multi packages

  • Participants
  • Parent commits ab6a76a

Comments (0)

Files changed (1)

File spotinstall.ml

 open Spotlib.Spot
 open Unix
 
-let package, verbose = 
+let packages, verbose = 
   match 
-    imp None (fun package -> 
+    imp [] (fun packages -> 
       imp_ false (fun verbose -> 
-        Arg.parse ["-v", Arg.Set verbose, "verbose"]  (fun x -> 
-          match !package with
-          | Some _ -> failwith "Only one package can be specified"
-          | None -> package := Some x) "spotinstall package"))
+        Arg.parse ["-v", Arg.Set verbose, "verbose"]  (fun x -> packages := x :: !packages)
+          "spotinstall <packages>"
+      ))
   with
-  | None, _ -> failwith "You must specify a package name"
-  | Some p, v -> p, v
+  | [], _ -> failwith "You must specify a package name"
+  | packages, v -> packages, v
 
 let ocamlfind_path = 
   match 
   | None -> failwith "No ocamlfind installtion path found. Check your ocamlfind."
   | Some p -> p
 
-let dest_dir = ocamlfind_path ^/ package
+let exts_of_sp = function
+  | ".cmx" | ".cmo" -> [ ".spot" ]
+  | ".cmi" -> [ ".spit"; ".spot" ] (* Packed .cmi has no .spit but .spot *)
+  | _ -> assert false
 
-let _ = Printf.eprintf "ocamlfind install dir: %s\n" dest_dir
-
-let installed_cms = 
-  let files = Hashtbl.create 107 in
+let find_installed_cms tbl dest_dir = 
   Unix.find [dest_dir] ~f:(fun path -> 
     match Filename.split_extension path.Unix.base with
     | body, (".cmx" | ".cmo" | ".cmi" as ext) -> 
         if verbose then Printf.eprintf "found %s\n" path.Unix.path;
-        Hashtbl.add files (body, ext) path.Unix.path
-    | _ -> ());
-  files
+        Hashtbl.add tbl (body, ext) path.Unix.path
+    | _ -> ())
+
+let dest_dir package= ocamlfind_path ^/ package
+
+let installed_cms = 
+  let tbl = Hashtbl.create 107 in
+  List.iter (fun package -> find_installed_cms tbl (dest_dir package)) packages;
+  tbl
+
+let _ = Printf.eprintf "ocamlfind packages: %s\n" (String.concat ", " packages)
 
 (* For each installed *.cm* file, we try to find the same file in the current directory,
    then copy the accompanied .spot/.spit *)
 
-let exts_of_sp = function
-  | ".cmx" | ".cmo" -> [ ".spot" ]
-  | ".cmi" -> [ ".spit"; ".spot" ] (* Packed .cmi has no .spit but .spot *)
-  | _ -> assert false
-
 let _ =
   let copied = Hashset.create 107 in