Commits

camlspotter  committed 38f46ff

uses ln by default

  • Participants
  • Parent commits 2016085

Comments (0)

Files changed (1)

File spotinstall.ml

   | Package s -> sprintf "package %s" s
   | Path s -> s
 
-let dests, verbose = 
-  match 
-    imp [] & fun dests -> 
-      imp_ false & fun verbose -> 
-        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)
+let dests, verbose, meth = 
+  let dests = ref [] in
+  let verbose = ref false in
+  let meth = Once.create () in
+    
+  Arg.parse 
+      [ "-v", Arg.Set verbose, "verbose"
+      ; "-c", Arg.Unit (fun () -> Once.set meth `Copy), "use cp"
+      ; "-l", Arg.Unit (fun () -> Once.set meth `Link), "use ln  (default)"
+      ; "-s", Arg.Unit (fun () -> Once.set meth `Sym),  "use ln -s"
+      ] 
+      (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
-  | [], v -> `All, v
-  | dests, v -> `Some dests, v
+           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.";
+    
+  let dests = match !dests with
+    | [] -> `All
+    | dests -> `Some dests
+  in
+  let verbose = !verbose in
+  let meth = match Once.get meth with
+      | Some v -> v
+      | None -> `Link
+  in
+  dests, verbose, meth
 
 module OCamlFind = struct
 
                 if not need_to_copy then
                   Hashset.add copied p                
                 else begin
+                  let comm = match meth with
+                    | `Copy -> ["/bin/cp"]
+                    | `Link -> ["/bin/ln"]
+                    | `Sym  -> ["/bin/ln"; "-s"]
+                  in
                   match 
-                    command ["/bin/cp"; spotspit; dirname] ~f:(function
-                      | (`Err, `Read mes) -> eprintf "Failed to copy %s to %s: %s\n%!" spotspit dirname mes
-                      | _ -> ())
+                    command (comm @ [spotspit; dirname])
+                      ~f:(function
+                        | (`Err, `Read mes) -> eprintf "Failed to install %s to %s: %s\n%!" spotspit dirname mes
+                        | _ -> ())
                   with
                   | `Exited 0 -> 
                       Hashset.add copied p;
-                      eprintf "Copied %s to %s\n%!" spotspit dirname
+                      eprintf "Installed %s to %s\n%!" spotspit dirname
                   | `Exited n -> 
-                      eprintf "cp returned with a strange status %d\n%!" n
-                  | _ -> eprintf "Failed to copy %s to %s: SOME STRANGE READON\n%!" spotspit dirname
+                      eprintf "%s returned with a strange status %d\n%!" 
+                        (String.concat " " comm)
+                        n
+                  | _ -> 
+                      eprintf "Failed to %s %s to %s: SOME STRANGE REASON\n%!" 
+                        (String.concat " " comm)
+                        spotspit dirname
                 end 
           ))
     | _ -> ());