Commits

camlspotter  committed f82da2d

added .spot to the candidates of copying for .cmi, for packed .cmo whose object file is only installed into .cma

  • Participants
  • Parent commits bc197af

Comments (0)

Files changed (1)

File spotinstall.ml

 (* For each installed *.cm* file, we try to find the same file in the current directory,
    then copy the accompanied .spot/.spit *)
 
-let ext_of_sp = function
-  | ".cmx" | ".cmo" -> ".spot"
-  | ".cmi" -> ".spit"
+let exts_of_sp = function
+  | ".cmx" | ".cmo" -> [ ".spot" ]
+  | ".cmi" -> [ ".spit"; ".spot" ] (* Packed .cmi has no .spit but .spot *)
   | _ -> assert false
 
 let _ =
   Unix.find ["."] ~f:(fun path ->
     match Filename.split_extension path.Unix.base with
     | body, (".cmx" | ".cmo" | ".cmi" as ext) -> 
-        let spotspit = path.Unix.dir ^/ body ^ ext_of_sp ext in
-        if Sys.file_exists spotspit then
-          let found = Hashtbl.find_all installed_cms (body, ext) in
-          List.iter (fun p -> 
-            match Unix.cmp p path.Unix.path with
-            | `Different | `Error -> ()
-            | `Same ->
-                (* The file is installed! If there is .spot/.spit, copy it! *)
-                let dirname = Filename.dirname p in
-                match 
-                  Unix.command ["cp"; spotspit; dirname] ~f:(function
-                    | (`Err, `Read mes) -> Printf.eprintf "Failed to copy %s to %s: %s\n" spotspit dirname mes
-                    | _ -> ())
-                with
-                | WEXITED 0 -> 
-                    Hashset.add copied p;
-                    Printf.eprintf "Copied %s to %s\n" spotspit dirname
-                | WEXITED _ -> ()
-                | _ -> Printf.eprintf "Failed to copy %s to %s: SOME STRANGE READON\n" spotspit dirname
-          ) found
+        begin match 
+            let spotspits = 
+              List.map (fun ext -> path.Unix.dir ^/ body ^ ext) (exts_of_sp ext)
+            in
+            try Some (List.find Sys.file_exists spotspits) with Not_found -> None
+        with
+        | None -> ()
+        | Some spotspit ->
+            let found = Hashtbl.find_all installed_cms (body, ext) in
+            List.iter (fun p -> 
+              match Unix.cmp p path.Unix.path with
+              | `Different | `Error -> ()
+              | `Same ->
+                  (* The file is installed! If there is .spot/.spit, copy it! *)
+                  let dirname = Filename.dirname p in
+                  match 
+                    Unix.command ["cp"; spotspit; dirname] ~f:(function
+                      | (`Err, `Read mes) -> Printf.eprintf "Failed to copy %s to %s: %s\n" spotspit dirname mes
+                      | _ -> ())
+                  with
+                  | WEXITED 0 -> 
+                      Hashset.add copied p;
+                      Printf.eprintf "Copied %s to %s\n" spotspit dirname
+                  | WEXITED _ -> ()
+                  | _ -> Printf.eprintf "Failed to copy %s to %s: SOME STRANGE READON\n" spotspit dirname
+            ) found
+        end
     | _ -> ());
 
   (* check not found *)