Commits

camlspotter  committed f88f905 Merge

merge

  • Participants
  • Parent commits 94778ab, e86154e

Comments (0)

Files changed (1)

File spotinstall.ml

 open Spotlib.Spot
 open Unix
 
-let packages, verbose = 
+type dest = 
+  | Package of string
+  | Path of string
+
+let dests, verbose = 
   match 
-    imp [] & fun packages -> 
+    imp [] & fun dests -> 
       imp_ false & fun verbose -> 
-        Arg.parse ["-v", Arg.Set verbose, "verbose"] (fun x -> packages := x :: !packages)
-          "spotinstall <packages>\n  \
-           Check the files installed as ocamlfind package <package>, and if there are corresponding .cmt/.cmti/.spot/.spit files in the current and sub directories, copy them to the installation directory."
+        Arg.parse 
+          ["-v", Arg.Set verbose, "verbose"] 
+          (fun x -> 
+            let d = if Filename.is_relative x then Package x else Path x in
+            dests := d :: !dests)
+          "spotinstall <packages-or-abs-paths>\n  \
+           Check the files installed as ocamlfind package <package>, or files in directory <abs-path> and if there are corresponding .cmt/.cmti/.spot/.spit files in the current and sub directories, copy them to the installation directory."
   with
-  | [], _ -> failwith "You must specify a package name"
-  | packages, v -> packages, v
+  | [], _ -> failwith "You must specify at least one package name or absolute path"
+  | dests, v -> dests, v
 
 let ocamlfind_path = 
   match 
   | None -> failwith "No ocamlfind installtion path found. Check your ocamlfind."
   | Some p -> p
 
+let ocamlfind_dest_dir package = 
+  match 
+    imp_ None & fun result ->
+      ignore & shell_command (Printf.sprintf "ocamlfind query %s" package) & 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
+        | _ -> ()
+  with
+  | None -> failwith "No ocamlfind installtion path for the package found. Check your ocamlfind."
+  | Some p -> p
+
 let ocaml_where = 
   match 
     imp_ None & fun ocaml_where ->
   | ".ml" -> [ ".annot" ]
   | _ -> assert false
 
-let dest_dir package= ocamlfind_path ^/ package
-
 let find_installed_cms tbl package =
-  let dest_dir = match package with "ocaml" -> ocaml_where | _ -> dest_dir package in
+  let dest_dir = match package with 
+    | Package "ocaml" -> ocaml_where 
+    | Package package -> ocamlfind_dest_dir package 
+    | Path p -> p
+  in
   Unix.find [dest_dir] &~ fun path -> 
-    if path.Unix.base = "site-lib" && package = "ocaml" then Unix.prune ()
+    if path.Unix.base = "site-lib" && package = Package "ocaml" then 
+      Unix.prune ()
     else 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;
 
 let installed_cms = 
   let tbl = Hashtbl.create 107 in
-  List.iter (fun package -> find_installed_cms tbl package) packages;
+  List.iter (fun package -> find_installed_cms tbl package) dests;
   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 *)