Browse thread
ocamlbuild and adding files to be sanitized
-
erickt@d...
- Erick Tryzelaar
- Nicolas Pouillard
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Erick Tryzelaar <erickt@d...> |
| Subject: | Re: [Caml-list] ocamlbuild and adding files to be sanitized |
erickt@dslextreme.com wrote:
> I'm finishing up getting ocamlbuild to work with the dypgen parser, but I
> can't yet figure out how to get ocamlbuild to automatically list the .ml
> and .mli of the .dyp parser as microbes to be cleaned in sanitize.sh. It
> doesn't look like the hygiene or fda modules are exposed in the plugin. Is
> there any way to do it other than manually replicate the functionality in
> the {Before,After}_hygiene dispatch hook?
I was wrong, it looks like these modules are exposed, through
Ocamlbuild_pack. However, I cannot add sanitize rules to the already
existing set. I have to replicate the functionality with a dispatch
call, like this:
myocamlbuild.ml:
let laws =
[
{ law_name = "Leftover dypgen-generated files";
law_rules = [Implies_not(".dyp",".ml"); Implies_not(".dyp",".mli")];
law_penalty = Fail }
]
;;
dispatch begin function
| Before_rules ->
begin
let evil = ref false in
match !Options.entry with
| None -> ();
| Some entry ->
match check
?sanitize:
begin
if !Options.sanitize then
Some(!Options.sanitization_script)
else
None
end
laws entry
with
| [] -> ()
| stuff ->
List.iter
begin fun (law, msgs) ->
Printf.printf "%s: %s:\n"
(match law.law_penalty with
| Warn -> "Warning"
| Fail ->
if not !evil then
begin
Printf.printf "IMPORTANT: I cannot work with
leftover compiled files.\n%!";
evil := true;
end;
"ERROR")
law.law_name;
List.iter (Printf.printf " %s\n") msgs
end
stuff;
if !evil then raise Fda.Exit_hygiene_failed;
end
...
end;;
This is copied almost exactly from fda.ml, but since it's not exposed, I
can't use it. It would be great if the Fda module could model after the
Tags model, and have an interface like this:
fda.mli:
...
val law ?penalty:Hygiene.penalty -> string -> Hygiene.rule list
...
fda.ml:
...
let all_laws = ref [...]
let law ?(penalty=Fail) name rules =
all_laws := { law_name = name; law_rules = rules; law_penalty =
penalty } :: !all_laws
...
Then, I could easily replace my code with this:
myocamlbuild.ml:
open Ocamlbuild_pack.Fda;;
open Ocamlbuild_pack.Hygiene;;
law "Leftover dypgen-generated files" [Implies_not(".dyp",".ml");
Implies_not(".dyp",".mli")];;
dispatch begin function
...
end;;
Would this be useful for others?