Commits

camlspotter committed 21d724d

src_dir => src_file and added file existence test

  • Participants
  • Parent commits ef4c666
  • Branches 4.01.0.2.2.0

Comments (0)

Files changed (5)

 
 let comp_dir = Hashtbl.memoize (Hashtbl.create 107) comp_dir
 
-let src_dir fp0 =
+let src_file fp0 =
   if not (FP.is_absolute fp0) then fp0
   else
     match find_dot_ocamlspot fp0 with
             (* CR jfuruse: inefficient *)
             FP.of_string (Filename.concats (FP.to_string dir :: postfixes))
 
-let src_dir x =
-  let y = src_dir x in
+let src_file x =
+  let y = src_file x in
   if not (FP.equal x y) then
-    Format.eprintf "src_dir: %s => %s@." (FP.to_string x) (FP.to_string y);
+    Format.eprintf "src_file: %s => %s@." (FP.to_string x) (FP.to_string y);
   y
 
-let src_dir = Hashtbl.memoize (Hashtbl.create 107) src_dir
+(* No need of memoize
+let src_file = Hashtbl.memoize (Hashtbl.create 107) src_file
+*)
 (** ocamlbuild compilation directory tweak *)
 
 val comp_dir : Filepath.t -> Filepath.t
-(** ocaml/camlp4/Camlp4Bin.ml => ocaml/_build/camlp4/Camlp4Bin.ml *)
+(** ocaml/camlp4/Camlp4 => ocaml/_build/camlp4/Camlp *)
 
-val src_dir : Filepath.t -> Filepath.t
+val src_file : Filepath.t -> Filepath.t
 (** ocaml/_build/camlp4/Camlp4Bin.ml => ocaml/camlp4/Camlp4Bin.ml *)
   | (true, []) -> (true, [])
   | (abs, (_::xs)) -> (abs, xs)
 
+let wrap f s = to_string (f (of_string s))
 val dirbase : t -> t * string option
 val (^/) : t -> string -> t
 val parent : t -> t
+val wrap : (t -> t) -> string -> string
   module FP = Filepath
   let print_query_result kind = function
     | None -> printf "Spot: no spot@."
-    | Some (pident, res) -> match res with
+    | Some (pident, res) -> 
+        let src_file path =
+          let path' = FP.wrap Compdir.src_file path in
+          if path = path' then path 
+          else
+            if not (Sys.file_exists path') then begin
+              Format.eprintf "Warning: this is a source file in a build directory. No original file found at %s@." path';
+              path
+            end else path' (* CR jfuruse: we must check path and path' have the same contents *)
+        in
+        match res with
 	| File.File_itself ->
-            let path = FP.to_string (Compdir.src_dir (FP.of_string pident.PIdent.path)) in
+            let path = src_file pident.PIdent.path in
             printf "Spot: <%s:all>@." path
 	| File.Found_at (path, region) ->
-            let path = FP.to_string (Compdir.src_dir (FP.of_string path)) in
+            let path = src_file path in
             printf "Spot: <%s:%s>@."
               path
               (Region.to_string region)