caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Patch that adds -pp option to ocamldep
@ 2001-08-14 19:11 Paul Stodghill
  2001-08-14 19:53 ` Daniel de Rauglaudre
  0 siblings, 1 reply; 2+ messages in thread
From: Paul Stodghill @ 2001-08-14 19:11 UTC (permalink / raw)
  To: caml-list

Enjoy. Please let me know if you find any bugs in this.

--- tools/ocamldep.ml.ORIG	Fri Mar 23 11:57:45 2001
+++ tools/ocamldep.ml	Tue Aug 14 15:06:03 2001
@@ -319,7 +319,28 @@
 
 let error_occurred = ref false
 
-let file_dependencies source_file =
+let preprocessor = ref None
+
+let preprocess sourcefile =
+  match !preprocessor with
+    None -> sourcefile
+  | Some pp ->
+      let tmpfile = Filename.temp_file "camlpp" "" in
+      let comm = Printf.sprintf "%s %s > %s" pp sourcefile tmpfile in
+      if Sys.command  comm <> 0 then begin
+        Misc.remove_file tmpfile;
+        Printf.eprintf "Preprocessing error\n";
+        exit 2
+      end;
+      tmpfile
+
+let remove_preprocessed inputfile =
+  match !preprocessor with
+    None -> ()
+  | Some _ -> Misc.remove_file inputfile
+
+let file_dependencies raw_source_file =
+  let source_file = preprocess raw_source_file in
   Location.input_name := source_file;
   if Sys.file_exists source_file then begin
     try
@@ -327,9 +348,9 @@
       let ic = open_in_bin source_file in
       try
         let lb = Lexing.from_channel ic in
-        if Filename.check_suffix source_file ".ml" then begin
+        if Filename.check_suffix raw_source_file ".ml" then begin
           add_use_file StringSet.empty (Parse.use_file lb);
-          let basename = Filename.chop_suffix source_file ".ml" in
+          let basename = Filename.chop_suffix raw_source_file ".ml" in
           let init_deps =
             if Sys.file_exists (basename ^ ".mli")
             then let cmi_name = basename ^ ".cmi" in ([cmi_name], [cmi_name])
@@ -339,17 +360,17 @@
           print_dependencies (basename ^ ".cmo") byt_deps;
           print_dependencies (basename ^ ".cmx") opt_deps
         end else
-        if Filename.check_suffix source_file ".mli" then begin
+        if Filename.check_suffix raw_source_file ".mli" then begin
           add_signature StringSet.empty (Parse.interface lb);
-          let basename = Filename.chop_suffix source_file ".mli" in
+          let basename = Filename.chop_suffix raw_source_file ".mli" in
           let (byt_deps, opt_deps) =
             StringSet.fold find_dependency !free_structure_names ([], []) in
           print_dependencies (basename ^ ".cmi") byt_deps
         end else
           ();
-        close_in ic
+        close_in ic; remove_preprocessed source_file
       with x ->
-        close_in ic; raise x
+        close_in ic; remove_preprocessed source_file; raise x
     with x ->
       let report_err = function
       | Lexer.Error(err, start, stop) ->
@@ -375,6 +396,8 @@
   Arg.parse [
      "-I", Arg.String(fun dir -> load_path := !load_path @ [dir]),
        "<dir>  Add <dir> to the list of include directories";
+     "-pp", Arg.String(fun cmd -> preprocessor := Some(cmd)),
+       "<command>  Pipe sources through preprocessor <command>";
      "-native", Arg.Set native_only,
        "  Generate dependencies for a pure native-code project (no .cmo files)"
     ] file_dependencies usage;
milhouse$ 

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Patch that adds -pp option to ocamldep
  2001-08-14 19:11 [Caml-list] Patch that adds -pp option to ocamldep Paul Stodghill
@ 2001-08-14 19:53 ` Daniel de Rauglaudre
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel de Rauglaudre @ 2001-08-14 19:53 UTC (permalink / raw)
  To: Paul Stodghill; +Cc: caml-list

Hi,

On Tue, Aug 14, 2001 at 03:11:12PM -0400, Paul Stodghill wrote:

> Enjoy. Please let me know if you find any bugs in this.
> 
> --- tools/ocamldep.ml.ORIG	Fri Mar 23 11:57:45 2001
> +++ tools/ocamldep.ml	Tue Aug 14 15:06:03 2001

I already made it last week in the current version of OCaml! You can
see it in the CVS public version. Next distributed version will have
it.

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-08-14 19:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-14 19:11 [Caml-list] Patch that adds -pp option to ocamldep Paul Stodghill
2001-08-14 19:53 ` Daniel de Rauglaudre

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).